Unverified Commit 81a2e105 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

add mitigation for empty bounding boxes (#6923)

parent f30a92f1
...@@ -337,6 +337,9 @@ def _affine_bounding_box_xyxy( ...@@ -337,6 +337,9 @@ def _affine_bounding_box_xyxy(
center: Optional[List[float]] = None, center: Optional[List[float]] = None,
expand: bool = False, expand: bool = False,
) -> Tuple[torch.Tensor, Tuple[int, int]]: ) -> 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, shear, center = _affine_parse_args(
angle, translate, scale, shear, InterpolationMode.NEAREST, center angle, translate, scale, shear, InterpolationMode.NEAREST, center
) )
...@@ -1013,6 +1016,9 @@ def perspective_bounding_box( ...@@ -1013,6 +1016,9 @@ def perspective_bounding_box(
endpoints: Optional[List[List[int]]], endpoints: Optional[List[List[int]]],
coefficients: Optional[List[float]] = None, coefficients: Optional[List[float]] = None,
) -> torch.Tensor: ) -> torch.Tensor:
if bounding_box.numel() == 0:
return bounding_box
perspective_coeffs = _perspective_coefficients(startpoints, endpoints, coefficients) perspective_coeffs = _perspective_coefficients(startpoints, endpoints, coefficients)
original_shape = bounding_box.shape original_shape = bounding_box.shape
...@@ -1203,6 +1209,9 @@ def elastic_bounding_box( ...@@ -1203,6 +1209,9 @@ def elastic_bounding_box(
format: features.BoundingBoxFormat, format: features.BoundingBoxFormat,
displacement: torch.Tensor, displacement: torch.Tensor,
) -> torch.Tensor: ) -> torch.Tensor:
if bounding_box.numel() == 0:
return bounding_box
# TODO: add in docstring about approximation we are doing for grid inversion # TODO: add in docstring about approximation we are doing for grid inversion
displacement = displacement.to(bounding_box.device) displacement = displacement.to(bounding_box.device)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment