π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix: clarify unimplemented Boxes error messages (#4518)
victorwon200110118238a9f0
diff --git a/changelog.d/4518.fixed.md b/changelog.d/4518.fixed.mdnew file mode 100644index 000000000..976754504--- /dev/null+++ b/changelog.d/4518.fixed.md@@ -0,0 +1,2 @@+The unimplemented tuple-bound `Boxes.clamp`, `Boxes.trim`, and `Boxes.translate(method="fast")` paths now raise+`NotImplementedError` with actionable messages, including the supported tensor bounds and `warp` alternatives where applicable.diff --git a/kornia/geometry/boxes.py b/kornia/geometry/boxes.pyindex 9ffea38c5..6e15c606c 100644--- a/kornia/geometry/boxes.py+++ b/kornia/geometry/boxes.py@@ -559,7 +559,10 @@ class Boxes:provided bounds."""if not (isinstance(topleft, torch.Tensor) and isinstance(botright, torch.Tensor)):- raise NotImplementedError+ raise NotImplementedError(+ "`Boxes.clamp` accepts `topleft` and `botright` as `(B, 2)` torch.Tensor bounds; "+ f"got topleft={type(topleft).__name__} and botright={type(botright).__name__}."+ )if inplace:_data = self._dataelse:@@ -601,7 +604,7 @@ class Boxes:NotImplementedError: Always."""- raise NotImplementedError+ raise NotImplementedError("`Boxes.trim` is not implemented.")def filter_boxes_by_area(self, min_area: Optional[float] = None, max_area: Optional[float] = None, inplace: bool = False@@ -988,7 +991,9 @@ class Boxes:"""if method == "fast":- raise NotImplementedError+ raise NotImplementedError(+ "`Boxes.translate(method='fast')` is not implemented; use `method='warp'` instead."+ )if method != "warp":raise NotImplementedErrordiff --git a/tests/geometry/test_boxes.py b/tests/geometry/test_boxes.pyindex 054ae4a9a..1d62830f0 100644--- a/tests/geometry/test_boxes.py+++ b/tests/geometry/test_boxes.py@@ -728,7 +728,7 @@ class TestBoxes2D(BaseTester):torch.tensor([[[8.0, 9.0, 10.0, 11.0]]], device=device, dtype=dtype),mode="xyxy",)- with pytest.raises(NotImplementedError):+ with pytest.raises(NotImplementedError, match=r"\(B, 2\).*torch\.Tensor.*tuple"):boxes.clamp((0, 0), (5, 5))clamped = boxes.clamp(torch.tensor([[0.0, 0.0]], device=device, dtype=dtype),@@ -747,9 +747,9 @@ class TestBoxes2D(BaseTester):# Wart pin for kornia#4017: both documented entry points raise instead# of implementing their advertised operations.boxes = Boxes.from_tensor(torch.tensor([[[1.0, 2.0, 5.0, 4.0]]], device=device, dtype=dtype), mode="xyxy")- with pytest.raises(NotImplementedError):+ with pytest.raises(NotImplementedError, match=r"Boxes\.trim.*not implemented"):boxes.trim()- with pytest.raises(NotImplementedError):+ with pytest.raises(NotImplementedError, match=r"fast.*not implemented.*warp"):boxes.translate(torch.tensor([[1.0, 2.0]], device=device, dtype=dtype), method="fast")def test_convention_transform_boxes_in_place_rebinds_data(self, device, dtype):