Fix Pytorch3D PnP test

Summary:
EPnP fails the test when the number of points is below 6. As suggested, quadratic option is in theory to deal with as few as 4 points (so num_pts_thresh=3 is set). And when num_pts > num_pts_thresh=4, skip_q is False.

To avoid bumping num_pts_thresh while passing all the original tests, check_output is set to False when num_pts < 6, similar to the logic in Line 123-127.  It makes sure that the algo doesn't crash.

Reviewed By: shapovalov

Differential Revision: D37804438

fbshipit-source-id: 74576d63a9553e25e3ec344677edb6912b5f9354
This commit is contained in:
Jiali Duan 2022-07-14 09:50:39 -07:00 committed by Facebook GitHub Bot
parent 8e0c82b89a
commit 379c8b2780

View File

@ -54,9 +54,7 @@ class TestPerspectiveNPoints(TestCaseMixin, unittest.TestCase):
R_quat = rotation_conversions.matrix_to_quaternion(R)
num_pts = x_world.shape[-2]
# quadratic part is more stable with fewer points
num_pts_thresh = 5 if skip_q else 4
if check_output and num_pts > num_pts_thresh:
if check_output:
assert_msg = (
f"test_perspective_n_points assertion failure for "
f"n_points={num_pts}, "
@ -90,7 +88,12 @@ class TestPerspectiveNPoints(TestCaseMixin, unittest.TestCase):
print("R_hat | R_gt\n", R_gt)
print("T_hat | T_gt\n", T_gt)
def _testcase_from_2d(self, y, print_stats, benchmark, skip_q=False):
def _testcase_from_2d(
self, y, print_stats, benchmark, skip_q=False, skip_check_thresh=5
):
"""
In case num_pts < 6, EPnP gets unstable, so we check it doesn't crash
"""
x_cam, x_world, R, T = TestPerspectiveNPoints._generate_epnp_test_from_2d(
y[None].repeat(16, 1, 1)
)
@ -107,7 +110,15 @@ class TestPerspectiveNPoints(TestCaseMixin, unittest.TestCase):
return result
self._run_and_print(x_world, y, R, T, print_stats, skip_q, check_output=True)
self._run_and_print(
x_world,
y,
R,
T,
print_stats,
skip_q,
check_output=True if y.shape[1] > skip_check_thresh else False,
)
# in the noisy case, there are no guarantees, so we check it doesn't crash
if print_stats: