π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
test(epipolar): make random scene generation deterministic (#4891)
NiteeshGowda72c9a4f2b1918c
diff --git a/testing/geometry/create.py b/testing/geometry/create.pyindex 0ff1ff2b9..48a4e9ffc 100644--- a/testing/geometry/create.py+++ b/testing/geometry/create.py@@ -63,7 +63,9 @@ def generate_two_view_random_scene(num_views: int = 2num_points: int = 30- scene: dict[str, torch.Tensor] = epi.generate_scene(num_views, num_points)+ with torch.random.fork_rng():+ torch.manual_seed(4886)+ scene: dict[str, torch.Tensor] = epi.generate_scene(num_views, num_points)# internal parameters (same K)K1 = scene["K"].to(device, dtype)diff --git a/tests/geometry/epipolar/test_essential.py b/tests/geometry/epipolar/test_essential.pyindex d3ab6e830..29e09a557 100644--- a/tests/geometry/epipolar/test_essential.py+++ b/tests/geometry/epipolar/test_essential.py@@ -26,6 +26,20 @@ from testing.geometry.create import generate_two_view_random_scenefrom testing.two_view import two_view_scene+def test_generate_two_view_random_scene_is_deterministic():+ torch.manual_seed(123)+ expected_next = torch.rand(3)++ torch.manual_seed(123)+ scene1 = generate_two_view_random_scene()+ actual_next = torch.rand(3)++ for key in scene1:+ assert torch.equal(scene1[key], generate_two_view_random_scene()[key]), f"Scene mismatch for {key}"++ assert torch.equal(actual_next, expected_next)++class TestFindEssential(BaseTester):def test_smoke(self, device, dtype):points1 = torch.rand(1, 5, 2, device=device, dtype=dtype)