Skip to content

Commit 3de4122

Browse files
gkioxarifacebook-github-bot
authored andcommitted
lower eps
Summary: Lower the epsilon value in the IoU3D calculation to fix small numerical issue from GH#1082 Reviewed By: bottler Differential Revision: D34371597 fbshipit-source-id: 12443fa359b7755ef4ae60e9adf83734a1a295ae
1 parent 967a099 commit 3de4122

File tree

3 files changed

+79
-7
lines changed

3 files changed

+79
-7
lines changed

pytorch3d/csrc/iou_box3d/iou_utils.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <cstdio>
1313
#include "utils/float_math.cuh"
1414

15-
__constant__ const float kEpsilon = 1e-4;
15+
__constant__ const float kEpsilon = 1e-5;
1616

1717
/*
1818
_PLANES and _TRIS define the 4- and 3-connectivity

pytorch3d/csrc/iou_box3d/iou_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#include <type_traits>
1919
#include "utils/vec3.h"
2020

21-
const auto kEpsilon = 1e-4;
21+
const auto kEpsilon = 1e-5;
22+
2223
/*
2324
_PLANES and _TRIS define the 4- and 3-connectivity
2425
of the 8 box corners.

tests/test_iou_box3d.py

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
OBJECTRON_TO_PYTORCH3D_FACE_IDX = [0, 4, 6, 2, 1, 5, 7, 3]
2121
DATA_DIR = get_tests_dir() / "data"
2222
DEBUG = False
23+
EPS = 1e-5
2324

2425
UNIT_BOX = [
2526
[0, 0, 0],
@@ -386,6 +387,76 @@ def _test_iou(self, overlap_fn, device):
386387
vol, iou = overlap_fn(box13a[None], box13b[None])
387388
self.assertClose(vol, torch.tensor([[2.0]], device=vol.device, dtype=vol.dtype))
388389

390+
# 14th test: From GH issue #992
391+
# Random rotation, same boxes, iou should be 1.0
392+
corners = (
393+
torch.tensor(
394+
[
395+
[-1.0, -1.0, -1.0],
396+
[1.0, -1.0, -1.0],
397+
[1.0, 1.0, -1.0],
398+
[-1.0, 1.0, -1.0],
399+
[-1.0, -1.0, 1.0],
400+
[1.0, -1.0, 1.0],
401+
[1.0, 1.0, 1.0],
402+
[-1.0, 1.0, 1.0],
403+
],
404+
device=device,
405+
dtype=torch.float32,
406+
)
407+
* 0.5
408+
)
409+
yaw = torch.tensor(0.185)
410+
Rot = torch.tensor(
411+
[
412+
[torch.cos(yaw), 0.0, torch.sin(yaw)],
413+
[0.0, 1.0, 0.0],
414+
[-torch.sin(yaw), 0.0, torch.cos(yaw)],
415+
],
416+
dtype=torch.float32,
417+
device=device,
418+
)
419+
corners = (Rot.mm(corners.t())).t()
420+
vol, iou = overlap_fn(corners[None], corners[None])
421+
self.assertClose(
422+
iou, torch.tensor([[1.0]], device=vol.device, dtype=vol.dtype), atol=1e-2
423+
)
424+
425+
# 15th test: From GH issue #1082
426+
box15a = torch.tensor(
427+
[
428+
[-2.5629019, 4.13995749, -1.76344576],
429+
[1.92329434, 4.28127117, -1.86155124],
430+
[1.86994571, 5.97489644, -1.86155124],
431+
[-2.61625053, 5.83358276, -1.76344576],
432+
[-2.53123587, 4.14095496, -0.31397536],
433+
[1.95496037, 4.28226864, -0.41208084],
434+
[1.90161174, 5.97589391, -0.41208084],
435+
[-2.5845845, 5.83458023, -0.31397536],
436+
],
437+
device=device,
438+
dtype=torch.float32,
439+
)
440+
441+
box15b = torch.tensor(
442+
[
443+
[-2.6256125, 4.13036357, -1.82893437],
444+
[1.87201008, 4.25296695, -1.82893437],
445+
[1.82562476, 5.95458116, -1.82893437],
446+
[-2.67199782, 5.83197777, -1.82893437],
447+
[-2.6256125, 4.13036357, -0.40095884],
448+
[1.87201008, 4.25296695, -0.40095884],
449+
[1.82562476, 5.95458116, -0.40095884],
450+
[-2.67199782, 5.83197777, -0.40095884],
451+
],
452+
device=device,
453+
dtype=torch.float32,
454+
)
455+
vol, iou = overlap_fn(box15a[None], box15b[None])
456+
self.assertClose(
457+
iou, torch.tensor([[0.91]], device=vol.device, dtype=vol.dtype), atol=1e-2
458+
)
459+
389460
def _test_real_boxes(self, overlap_fn, device):
390461
data_filename = "./real_boxes.pkl"
391462
with open(DATA_DIR / data_filename, "rb") as f:
@@ -643,7 +714,7 @@ def get_plane_verts(box: torch.Tensor) -> torch.Tensor:
643714
return plane_verts
644715

645716

646-
def box_planar_dir(box: torch.Tensor, eps=1e-4) -> torch.Tensor:
717+
def box_planar_dir(box: torch.Tensor, eps: float = 1e-4) -> torch.Tensor:
647718
"""
648719
Finds the unit vector n which is perpendicular to each plane in the box
649720
and points towards the inside of the box.
@@ -776,7 +847,7 @@ def box_volume(box: torch.Tensor) -> torch.Tensor:
776847
return vols
777848

778849

779-
def coplanar_tri_faces(tri1: torch.Tensor, tri2: torch.Tensor, eps: float = 1e-5):
850+
def coplanar_tri_faces(tri1: torch.Tensor, tri2: torch.Tensor, eps: float = EPS):
780851
"""
781852
Determines whether two triangle faces in 3D are coplanar
782853
Args:
@@ -803,7 +874,7 @@ def is_inside(
803874
n: torch.Tensor,
804875
points: torch.Tensor,
805876
return_proj: bool = True,
806-
eps: float = 1e-4,
877+
eps: float = EPS,
807878
):
808879
"""
809880
Computes whether point is "inside" the plane.
@@ -911,7 +982,7 @@ def clip_tri_by_plane_oneout(
911982
vout: torch.Tensor,
912983
vin1: torch.Tensor,
913984
vin2: torch.Tensor,
914-
eps: float = 1e-6,
985+
eps: float = EPS,
915986
) -> Tuple[torch.Tensor, torch.Tensor]:
916987
"""
917988
Case (a).
@@ -950,7 +1021,7 @@ def clip_tri_by_plane_twoout(
9501021
vout1: torch.Tensor,
9511022
vout2: torch.Tensor,
9521023
vin: torch.Tensor,
953-
eps: float = 1e-6,
1024+
eps: float = EPS,
9541025
) -> Tuple[torch.Tensor, torch.Tensor]:
9551026
"""
9561027
Case (b).

0 commit comments

Comments
 (0)