Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
a52607ec
You need to sign in or sign up before continuing.
Unverified
Commit
a52607ec
authored
Feb 09, 2024
by
Nicolas Hug
Committed by
GitHub
Feb 09, 2024
Browse files
Fix convert_bounding_box_format when passing strings (#8265)
parent
81e2831a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
test/test_transforms_v2.py
test/test_transforms_v2.py
+17
-0
torchvision/transforms/v2/_meta.py
torchvision/transforms/v2/_meta.py
+1
-3
torchvision/transforms/v2/functional/_meta.py
torchvision/transforms/v2/functional/_meta.py
+5
-0
No files found.
test/test_transforms_v2.py
View file @
a52607ec
...
@@ -3398,6 +3398,23 @@ class TestConvertBoundingBoxFormat:
...
@@ -3398,6 +3398,23 @@ class TestConvertBoundingBoxFormat:
make_bounding_boxes
(
format
=
old_format
),
make_bounding_boxes
(
format
=
old_format
),
)
)
@
pytest
.
mark
.
parametrize
((
"old_format"
,
"new_format"
),
old_new_formats
)
def
test_strings
(
self
,
old_format
,
new_format
):
# Non-regression test for https://github.com/pytorch/vision/issues/8258
input
=
tv_tensors
.
BoundingBoxes
(
torch
.
tensor
([[
10
,
10
,
20
,
20
]]),
format
=
old_format
,
canvas_size
=
(
50
,
50
))
expected
=
self
.
_reference_convert_bounding_box_format
(
input
,
new_format
)
old_format
=
old_format
.
name
new_format
=
new_format
.
name
out_functional
=
F
.
convert_bounding_box_format
(
input
,
new_format
=
new_format
)
out_functional_tensor
=
F
.
convert_bounding_box_format
(
input
.
as_subclass
(
torch
.
Tensor
),
old_format
=
old_format
,
new_format
=
new_format
)
out_transform
=
transforms
.
ConvertBoundingBoxFormat
(
new_format
)(
input
)
for
out
in
(
out_functional
,
out_functional_tensor
,
out_transform
):
assert_equal
(
out
,
expected
)
def
_reference_convert_bounding_box_format
(
self
,
bounding_boxes
,
new_format
):
def
_reference_convert_bounding_box_format
(
self
,
bounding_boxes
,
new_format
):
return
tv_tensors
.
wrap
(
return
tv_tensors
.
wrap
(
torchvision
.
ops
.
box_convert
(
torchvision
.
ops
.
box_convert
(
...
...
torchvision/transforms/v2/_meta.py
View file @
a52607ec
...
@@ -17,12 +17,10 @@ class ConvertBoundingBoxFormat(Transform):
...
@@ -17,12 +17,10 @@ class ConvertBoundingBoxFormat(Transform):
def
__init__
(
self
,
format
:
Union
[
str
,
tv_tensors
.
BoundingBoxFormat
])
->
None
:
def
__init__
(
self
,
format
:
Union
[
str
,
tv_tensors
.
BoundingBoxFormat
])
->
None
:
super
().
__init__
()
super
().
__init__
()
if
isinstance
(
format
,
str
):
format
=
tv_tensors
.
BoundingBoxFormat
[
format
]
self
.
format
=
format
self
.
format
=
format
def
_transform
(
self
,
inpt
:
tv_tensors
.
BoundingBoxes
,
params
:
Dict
[
str
,
Any
])
->
tv_tensors
.
BoundingBoxes
:
def
_transform
(
self
,
inpt
:
tv_tensors
.
BoundingBoxes
,
params
:
Dict
[
str
,
Any
])
->
tv_tensors
.
BoundingBoxes
:
return
F
.
convert_bounding_box_format
(
inpt
,
new_format
=
self
.
format
)
# type: ignore[return-value]
return
F
.
convert_bounding_box_format
(
inpt
,
new_format
=
self
.
format
)
# type: ignore[return-value
, arg-type
]
class
ClampBoundingBoxes
(
Transform
):
class
ClampBoundingBoxes
(
Transform
):
...
...
torchvision/transforms/v2/functional/_meta.py
View file @
a52607ec
...
@@ -214,6 +214,11 @@ def convert_bounding_box_format(
...
@@ -214,6 +214,11 @@ def convert_bounding_box_format(
if
not
torch
.
jit
.
is_scripting
():
if
not
torch
.
jit
.
is_scripting
():
_log_api_usage_once
(
convert_bounding_box_format
)
_log_api_usage_once
(
convert_bounding_box_format
)
if
isinstance
(
old_format
,
str
):
old_format
=
BoundingBoxFormat
[
old_format
.
upper
()]
if
isinstance
(
new_format
,
str
):
new_format
=
BoundingBoxFormat
[
new_format
.
upper
()]
if
torch
.
jit
.
is_scripting
()
or
is_pure_tensor
(
inpt
):
if
torch
.
jit
.
is_scripting
()
or
is_pure_tensor
(
inpt
):
if
old_format
is
None
:
if
old_format
is
None
:
raise
ValueError
(
"For pure tensor inputs, `old_format` has to be passed."
)
raise
ValueError
(
"For pure tensor inputs, `old_format` has to be passed."
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment