Skip to content

Commit c5ab007

Browse files
Yosua Michael Maranathafacebook-github-bot
authored andcommitted
[fbsync] add mitigation for empty bounding boxes (#6923)
Reviewed By: NicolasHug Differential Revision: D41265191 fbshipit-source-id: f0fdaf2cd6155cdb309edfaae25c486f2352a2d5
1 parent c69d2f1 commit c5ab007

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

torchvision/prototype/transforms/functional/_geometry.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ def _affine_bounding_box_xyxy(
337337
center: Optional[List[float]] = None,
338338
expand: bool = False,
339339
) -> Tuple[torch.Tensor, Tuple[int, int]]:
340+
if bounding_box.numel() == 0:
341+
return bounding_box, spatial_size
342+
340343
angle, translate, shear, center = _affine_parse_args(
341344
angle, translate, scale, shear, InterpolationMode.NEAREST, center
342345
)
@@ -1013,6 +1016,9 @@ def perspective_bounding_box(
10131016
endpoints: Optional[List[List[int]]],
10141017
coefficients: Optional[List[float]] = None,
10151018
) -> torch.Tensor:
1019+
if bounding_box.numel() == 0:
1020+
return bounding_box
1021+
10161022
perspective_coeffs = _perspective_coefficients(startpoints, endpoints, coefficients)
10171023

10181024
original_shape = bounding_box.shape
@@ -1203,6 +1209,9 @@ def elastic_bounding_box(
12031209
format: features.BoundingBoxFormat,
12041210
displacement: torch.Tensor,
12051211
) -> torch.Tensor:
1212+
if bounding_box.numel() == 0:
1213+
return bounding_box
1214+
12061215
# TODO: add in docstring about approximation we are doing for grid inversion
12071216
displacement = displacement.to(bounding_box.device)
12081217

0 commit comments

Comments
 (0)