20
20
OBJECTRON_TO_PYTORCH3D_FACE_IDX = [0 , 4 , 6 , 2 , 1 , 5 , 7 , 3 ]
21
21
DATA_DIR = get_tests_dir () / "data"
22
22
DEBUG = False
23
+ EPS = 1e-5
23
24
24
25
UNIT_BOX = [
25
26
[0 , 0 , 0 ],
@@ -386,6 +387,76 @@ def _test_iou(self, overlap_fn, device):
386
387
vol , iou = overlap_fn (box13a [None ], box13b [None ])
387
388
self .assertClose (vol , torch .tensor ([[2.0 ]], device = vol .device , dtype = vol .dtype ))
388
389
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
+
389
460
def _test_real_boxes (self , overlap_fn , device ):
390
461
data_filename = "./real_boxes.pkl"
391
462
with open (DATA_DIR / data_filename , "rb" ) as f :
@@ -643,7 +714,7 @@ def get_plane_verts(box: torch.Tensor) -> torch.Tensor:
643
714
return plane_verts
644
715
645
716
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 :
647
718
"""
648
719
Finds the unit vector n which is perpendicular to each plane in the box
649
720
and points towards the inside of the box.
@@ -776,7 +847,7 @@ def box_volume(box: torch.Tensor) -> torch.Tensor:
776
847
return vols
777
848
778
849
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 ):
780
851
"""
781
852
Determines whether two triangle faces in 3D are coplanar
782
853
Args:
@@ -803,7 +874,7 @@ def is_inside(
803
874
n : torch .Tensor ,
804
875
points : torch .Tensor ,
805
876
return_proj : bool = True ,
806
- eps : float = 1e-4 ,
877
+ eps : float = EPS ,
807
878
):
808
879
"""
809
880
Computes whether point is "inside" the plane.
@@ -911,7 +982,7 @@ def clip_tri_by_plane_oneout(
911
982
vout : torch .Tensor ,
912
983
vin1 : torch .Tensor ,
913
984
vin2 : torch .Tensor ,
914
- eps : float = 1e-6 ,
985
+ eps : float = EPS ,
915
986
) -> Tuple [torch .Tensor , torch .Tensor ]:
916
987
"""
917
988
Case (a).
@@ -950,7 +1021,7 @@ def clip_tri_by_plane_twoout(
950
1021
vout1 : torch .Tensor ,
951
1022
vout2 : torch .Tensor ,
952
1023
vin : torch .Tensor ,
953
- eps : float = 1e-6 ,
1024
+ eps : float = EPS ,
954
1025
) -> Tuple [torch .Tensor , torch .Tensor ]:
955
1026
"""
956
1027
Case (b).
0 commit comments