π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix(geometry): correct dimension labels in crop_by_boxes3d error message (#6406)
Rind4fe327b125d
diff --git a/changelog.d/6406.fixed.md b/changelog.d/6406.fixed.mdnew file mode 100644index 000000000..04895a823--- /dev/null+++ b/changelog.d/6406.fixed.md@@ -0,0 +1 @@+Corrected the dimension labels in the `crop_by_boxes3d` batch error message to match `(depth, height, width)`.diff --git a/kornia/geometry/transform/crop3d.py b/kornia/geometry/transform/crop3d.pyindex b4ab50bd7..ba96a82f7 100644--- a/kornia/geometry/transform/crop3d.py+++ b/kornia/geometry/transform/crop3d.py@@ -430,8 +430,8 @@ def crop_by_boxes3d(bbox = infer_bbox_shape3d(dst_box)if not ((bbox[0] == bbox[0][0]).all() and (bbox[1] == bbox[1][0]).all() and (bbox[2] == bbox[2][0]).all()):raise AssertionError(- "Cropping height, width and depth must be exact same in a batch."- f"Got height {bbox[0]}, width {bbox[1]} and depth {bbox[2]}."+ "Cropping depth, height and width must be exact same in a batch. "+ f"Got depth {bbox[0]}, height {bbox[1]} and width {bbox[2]}.")out_size = (int(bbox[0][0].item()), int(bbox[1][0].item()), int(bbox[2][0].item()))diff --git a/tests/geometry/transform/test_crop3d.py b/tests/geometry/transform/test_crop3d.pyindex b939debf1..61f40934a 100644--- a/tests/geometry/transform/test_crop3d.py+++ b/tests/geometry/transform/test_crop3d.py@@ -446,6 +446,71 @@ class TestCropByBoxes3D(BaseTester):)assert not torch.allclose(out_default, out_border, atol=1e-2, rtol=1e-2)+ def test_mismatched_batch_error_labels_dimensions_correctly(self, device, dtype):+ # Regression for #6402: the error message used to print depth as "height" and vice versa.+ inp = torch.rand(2, 1, 4, 4, 4, device=device, dtype=dtype)+ src_box = torch.tensor(+ [+ [+ [0.0, 0.0, 0.0],+ [3.0, 0.0, 0.0],+ [3.0, 3.0, 0.0],+ [0.0, 3.0, 0.0],+ [0.0, 0.0, 3.0],+ [3.0, 0.0, 3.0],+ [3.0, 3.0, 3.0],+ [0.0, 3.0, 3.0],+ ],+ [+ [0.0, 0.0, 0.0],+ [3.0, 0.0, 0.0],+ [3.0, 3.0, 0.0],+ [0.0, 3.0, 0.0],+ [0.0, 0.0, 3.0],+ [3.0, 0.0, 3.0],+ [3.0, 3.0, 3.0],+ [0.0, 3.0, 3.0],+ ],+ ],+ device=device,+ dtype=dtype,+ )+ # Batch item 0: 2x3x4 (depth=2, height=3, width=4)+ # Batch item 1: 3x3x4 (depth=3, height=3, width=4)+ # Depths differ across the batch, so the error should mention "depth".+ dst_box = torch.tensor(+ [+ [+ [0.0, 0.0, 0.0],+ [3.0, 0.0, 0.0],+ [3.0, 2.0, 0.0],+ [0.0, 2.0, 0.0],+ [0.0, 0.0, 1.0],+ [3.0, 0.0, 1.0],+ [3.0, 2.0, 1.0],+ [0.0, 2.0, 1.0],+ ],+ [+ [0.0, 0.0, 0.0],+ [3.0, 0.0, 0.0],+ [3.0, 2.0, 0.0],+ [0.0, 2.0, 0.0],+ [0.0, 0.0, 2.0],+ [3.0, 0.0, 2.0],+ [3.0, 2.0, 2.0],+ [0.0, 2.0, 2.0],+ ],+ ],+ device=device,+ dtype=dtype,+ )+ # Heights are 3 and widths 4 in both items, so the match also pins the height and width labels.+ with pytest.raises(+ AssertionError,+ match=r"Got depth tensor\(\[2\., 3\.\].*, height tensor\(\[3\., 3\.\].* and width tensor\(\[4\., 4\.\]",+ ):+ kornia.geometry.transform.crop_by_boxes3d(inp, src_box, dst_box)+class TestCrop3DSizeValidation:"""Tests that 3D crop functions properly reject invalid size arguments."""