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
f7c7bdf5
Unverified
Commit
f7c7bdf5
authored
Aug 24, 2023
by
Nicolas Hug
Committed by
GitHub
Aug 24, 2023
Browse files
Stricter SanitizeBoundingBoxes labels_getter heuristic (#7880)
parent
054432d2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
5 deletions
+18
-5
gallery/v2_transforms/plot_transforms_v2.py
gallery/v2_transforms/plot_transforms_v2.py
+3
-4
test/test_transforms_v2.py
test/test_transforms_v2.py
+14
-0
torchvision/transforms/v2/_utils.py
torchvision/transforms/v2/_utils.py
+1
-1
No files found.
gallery/v2_transforms/plot_transforms_v2.py
View file @
f7c7bdf5
...
...
@@ -99,10 +99,9 @@ bboxes = datapoints.BoundingBoxes(
format
=
"XYXY"
,
canvas_size
=
img
.
shape
[
-
2
:])
transforms
=
v2
.
Compose
([
v2
.
RandomPhotometricDistort
(),
v2
.
RandomIoUCrop
(),
v2
.
RandomHorizontalFlip
(
p
=
0.5
),
v2
.
SanitizeBoundingBoxes
(),
v2
.
RandomResizedCrop
(
size
=
(
224
,
224
),
antialias
=
True
),
v2
.
RandomPhotometricDistort
(
p
=
1
),
v2
.
RandomHorizontalFlip
(
p
=
1
),
])
out_img
,
out_bboxes
=
transforms
(
img
,
bboxes
)
...
...
test/test_transforms_v2.py
View file @
f7c7bdf5
...
...
@@ -1256,6 +1256,20 @@ def test_sanitize_bounding_boxes(min_size, labels_getter, sample_type):
assert
out_labels
.
tolist
()
==
valid_indices
def
test_sanitize_bounding_boxes_no_label
():
# Non-regression test for https://github.com/pytorch/vision/issues/7878
img
=
make_image
()
boxes
=
make_bounding_boxes
()
with
pytest
.
raises
(
ValueError
,
match
=
"or a two-tuple whose second item is a dict"
):
transforms
.
SanitizeBoundingBoxes
()(
img
,
boxes
)
out_img
,
out_boxes
=
transforms
.
SanitizeBoundingBoxes
(
labels_getter
=
None
)(
img
,
boxes
)
assert
isinstance
(
out_img
,
datapoints
.
Image
)
assert
isinstance
(
out_boxes
,
datapoints
.
BoundingBoxes
)
def
test_sanitize_bounding_boxes_errors
():
good_bbox
=
datapoints
.
BoundingBoxes
(
...
...
torchvision/transforms/v2/_utils.py
View file @
f7c7bdf5
...
...
@@ -112,7 +112,7 @@ def _find_labels_default_heuristic(inputs: Any) -> torch.Tensor:
inputs
=
inputs
[
1
]
# MixUp, CutMix
if
is
instance
(
inputs
,
torch
.
Tensor
):
if
is
_pure_tensor
(
inputs
):
return
inputs
if
not
isinstance
(
inputs
,
collections
.
abc
.
Mapping
):
...
...
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