mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2026-02-07 06:22:19 +08:00
small fix for iou3d
Summary: A small numerical fix for IoU for 3D boxes, fixes GH #992 * Adds a check for boxes with zero side areas (invalid boxes) * Fixes numerical issue when two boxes have coplanar sides Reviewed By: nikhilaravi Differential Revision: D33195691 fbshipit-source-id: 8a34b4d1f1e5ec2edb6d54143930da44bdde0906
This commit is contained in:
committed by
Facebook GitHub Bot
parent
069c9fd759
commit
ccfb72cc50
@@ -69,6 +69,28 @@ def _check_coplanar(boxes: torch.Tensor, eps: float = 1e-4) -> None:
|
||||
return
|
||||
|
||||
|
||||
def _check_nonzero(boxes: torch.Tensor, eps: float = 1e-4) -> None:
|
||||
"""
|
||||
Checks that the sides of the box have a non zero area
|
||||
"""
|
||||
faces = torch.tensor(_box_triangles, dtype=torch.int64, device=boxes.device)
|
||||
# pyre-fixme[16]: `boxes` has no attribute `index_select`.
|
||||
verts = boxes.index_select(index=faces.view(-1), dim=1)
|
||||
B = boxes.shape[0]
|
||||
T, V = faces.shape
|
||||
# (B, T, 3, 3) -> (B, T, 3)
|
||||
v0, v1, v2 = verts.reshape(B, T, V, 3).unbind(2)
|
||||
|
||||
normals = torch.cross(v1 - v0, v2 - v0, dim=-1) # (B, T, 3)
|
||||
face_areas = normals.norm(dim=-1) / 2
|
||||
|
||||
if (face_areas < eps).any().item():
|
||||
msg = "Planes have zero areas"
|
||||
raise ValueError(msg)
|
||||
|
||||
return
|
||||
|
||||
|
||||
class _box3d_overlap(Function):
|
||||
"""
|
||||
Torch autograd Function wrapper for box3d_overlap C++/CUDA implementations.
|
||||
@@ -138,6 +160,8 @@ def box3d_overlap(
|
||||
|
||||
_check_coplanar(boxes1, eps)
|
||||
_check_coplanar(boxes2, eps)
|
||||
_check_nonzero(boxes1, eps)
|
||||
_check_nonzero(boxes2, eps)
|
||||
|
||||
# pyre-fixme[16]: `_box3d_overlap` has no attribute `apply`.
|
||||
vol, iou = _box3d_overlap.apply(boxes1, boxes2)
|
||||
|
||||
Reference in New Issue
Block a user