π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix(geometry): preserve xyzwhd dimension order (#4189)
Puttala Jeevan Kumarca778f0a258a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b5cc97931..6d5ddcf1b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -349,6 +349,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0`kernel_size >= 63` now raises: CPU used to return a usable-looking answer there while MPS silently returnedsomething else for the same call.+* Fix `Boxes3D.from_tensor(..., mode="xyzwhd")` to preserve width, height, and depth field order for asymmetric+ boxes. (#4189)+* `RandomTransplantation` and `RandomTransplantation3D` transplanted nothing on MPS when no `excluded_labels`were given: PyTorch's MPS backend evaluates `all()` over the empty excluded-label axis to an undefined value,usually `False`, so every donor label was filtered out and the output equalled the input. The filter is now skipped when there isdiff --git a/kornia/geometry/boxes.py b/kornia/geometry/boxes.pyindex f325415a7..954f15d3a 100644--- a/kornia/geometry/boxes.py+++ b/kornia/geometry/boxes.py@@ -1154,7 +1154,7 @@ class Boxes3D:height = boxes[..., 4] - boxes[..., 1] + 1depth = boxes[..., 5] - boxes[..., 2] + 1elif mode == "xyzwhd":- depth, height, width = boxes[..., 4], boxes[..., 3], boxes[..., 5]+ width, height, depth = boxes[..., 3], boxes[..., 4], boxes[..., 5]else:raise ValueError(f"Unknown mode {mode}")diff --git a/tests/geometry/test_boxes.py b/tests/geometry/test_boxes.pyindex 395be3361..5276d94a2 100644--- a/tests/geometry/test_boxes.py+++ b/tests/geometry/test_boxes.py@@ -796,12 +796,12 @@ class TestBbox3D(BaseTester):@pytest.mark.parametrize("shape", [(1, 6), (1, 1, 6)])def test_from_tensor(self, shape, device, dtype):- box_xyzxyz = torch.as_tensor([[1, 2, 3, 4, 5, 6]], device=device, dtype=dtype).view(*shape)- box_xyzxyz_plus = torch.as_tensor([[1, 2, 3, 3, 4, 5]], device=device, dtype=dtype).view(*shape)- box_xyzwhd = torch.as_tensor([[1, 2, 3, 3, 3, 3]], device=device, dtype=dtype).view(*shape)+ box_xyzxyz = torch.as_tensor([[1, 2, 3, 3, 5, 7]], device=device, dtype=dtype).view(*shape)+ box_xyzxyz_plus = torch.as_tensor([[1, 2, 3, 2, 4, 6]], device=device, dtype=dtype).view(*shape)+ box_xyzwhd = torch.as_tensor([[1, 2, 3, 2, 3, 4]], device=device, dtype=dtype).view(*shape)expected_box = torch.as_tensor(- [[[1, 2, 3], [3, 2, 3], [3, 4, 3], [1, 4, 3], [1, 2, 5], [3, 2, 5], [3, 4, 5], [1, 4, 5]]], # Front # Back+ [[[1, 2, 3], [2, 2, 3], [2, 4, 3], [1, 4, 3], [1, 2, 6], [2, 2, 6], [2, 4, 6], [1, 4, 6]]], # Front # Backdevice=device,dtype=dtype,).view(*shape[:-1], 8, 3)