Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

compute_area fix for ndim=3 tensors (#2915)

Isalia2087f01f654f64
diff --git a/kornia/geometry/boxes.py b/kornia/geometry/boxes.py
index 8da512f29..c08ba867d 100644
--- a/kornia/geometry/boxes.py
+++ b/kornia/geometry/boxes.py
@@ -392,9 +392,9 @@ class Boxes:
def compute_area(self) -> torch.Tensor:
"""Returns :math:`(B, N)`."""
- w = self._data[:, :, 1, 0] - self._data[:, :, 0, 0]
- h = self._data[:, :, 2, 1] - self._data[:, :, 0, 1]
- return w * h
+ w = self._data[..., 1, 0] - self._data[..., 0, 0]
+ h = self._data[..., 2, 1] - self._data[..., 0, 1]
+ return (w * h).unsqueeze(0) if self._data.ndim == 3 else (w * h)
@classmethod
def from_tensor(