From b39a5c7302f011957cd6facd7819646a10d28d89 Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Mon, 7 Nov 2022 16:49:38 +0100 Subject: [PATCH] add mitigation for empty bounding boxes --- torchvision/prototype/transforms/functional/_geometry.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/torchvision/prototype/transforms/functional/_geometry.py b/torchvision/prototype/transforms/functional/_geometry.py index 09a9900f052..2f3039c8ccb 100644 --- a/torchvision/prototype/transforms/functional/_geometry.py +++ b/torchvision/prototype/transforms/functional/_geometry.py @@ -337,6 +337,9 @@ def _affine_bounding_box_xyxy( center: Optional[List[float]] = None, expand: bool = False, ) -> Tuple[torch.Tensor, Tuple[int, int]]: + if bounding_box.numel() == 0: + return bounding_box, spatial_size + angle, translate, shear, center = _affine_parse_args( angle, translate, scale, shear, InterpolationMode.NEAREST, center ) @@ -1013,6 +1016,9 @@ def perspective_bounding_box( endpoints: Optional[List[List[int]]], coefficients: Optional[List[float]] = None, ) -> torch.Tensor: + if bounding_box.numel() == 0: + return bounding_box + perspective_coeffs = _perspective_coefficients(startpoints, endpoints, coefficients) original_shape = bounding_box.shape @@ -1203,6 +1209,9 @@ def elastic_bounding_box( format: features.BoundingBoxFormat, displacement: torch.Tensor, ) -> torch.Tensor: + if bounding_box.numel() == 0: + return bounding_box + # TODO: add in docstring about approximation we are doing for grid inversion displacement = displacement.to(bounding_box.device)