Skip to content

Commit a4ee8dd

Browse files
authored
Make Gaussian splatting tests more device-agnostic (#311)
The save/load PLY tests currently assume that `self.device` is the same as the default `"cuda"` device. In addition, the projection tests assume that the device being tested is the same as the device stored within the checkpoint. Relax both of these assumption in preparation for introducing mGPU tests. Current test behavior is unchanged. --------- Signed-off-by: Matthew Cong <mcong@nvidia.com>
1 parent 5162d4b commit a4ee8dd

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

tests/unit/test_gaussian_splat_3d.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def test_load_ply_with_no_shN(self):
11501150
)
11511151
gs3d_no_shN.save_ply(tf.name)
11521152

1153-
gs3d_loaded, metadata = GaussianSplat3d.from_ply(tf.name)
1153+
gs3d_loaded, metadata = GaussianSplat3d.from_ply(tf.name, device=self.device)
11541154

11551155
self.assertTrue(torch.allclose(gs3d_loaded.means, gs3d_no_shN.means))
11561156
self.assertTrue(torch.allclose(gs3d_loaded.quats, gs3d_no_shN.quats))
@@ -1247,7 +1247,7 @@ def test_save_and_load_ply(self):
12471247

12481248
self.gs3d.save_ply(tf.name)
12491249

1250-
gs3d_loaded, metadata = GaussianSplat3d.from_ply(tf.name)
1250+
gs3d_loaded, metadata = GaussianSplat3d.from_ply(tf.name, device=self.device)
12511251

12521252
self.assertTrue(torch.allclose(gs3d_loaded.means, self.gs3d.means))
12531253
self.assertTrue(torch.allclose(gs3d_loaded.quats, self.gs3d.quats))
@@ -1278,7 +1278,7 @@ def test_save_and_load_ply_with_training_info(self):
12781278
}
12791279
self.gs3d.save_ply(tf.name, metadata=metadata_dict)
12801280

1281-
gs3d_loaded, training_info = GaussianSplat3d.from_ply(tf.name)
1281+
gs3d_loaded, training_info = GaussianSplat3d.from_ply(tf.name, device=self.device)
12821282

12831283
self.assertTrue(torch.allclose(gs3d_loaded.means, self.gs3d.means))
12841284
self.assertTrue(torch.allclose(gs3d_loaded.quats, self.gs3d.quats))
@@ -1305,7 +1305,7 @@ def test_save_ply_only_string_keys(self):
13051305
metadata_dict = {"_a_key_key": "foo bar baz", "anotherkey": "qux quux corge"}
13061306
self.gs3d.save_ply(tf.name, metadata=metadata_dict)
13071307

1308-
gs, meta = GaussianSplat3d.from_ply(tf.name)
1308+
gs, meta = GaussianSplat3d.from_ply(tf.name, device=self.device)
13091309
self.assertEqual(meta["_a_key_key"], "foo bar baz")
13101310
self.assertEqual(meta["anotherkey"], "qux quux corge")
13111311

@@ -1315,7 +1315,7 @@ def test_save_ply_only_int_keys(self):
13151315
metadata_dict = {"_a_key_key": 42, "anotherkey": sys.maxsize}
13161316
self.gs3d.save_ply(tf.name, metadata=metadata_dict)
13171317

1318-
gs, meta = GaussianSplat3d.from_ply(tf.name)
1318+
gs, meta = GaussianSplat3d.from_ply(tf.name, device=self.device)
13191319
self.assertEqual(meta["_a_key_key"], 42)
13201320
self.assertEqual(meta["anotherkey"], sys.maxsize)
13211321

@@ -1353,7 +1353,7 @@ def test_save_and_load_ply_with_training_info_non_contiguous(self):
13531353
}
13541354
self.gs3d.save_ply(tf.name, metadata_dict)
13551355

1356-
gs3d_loaded, training_info = GaussianSplat3d.from_ply(tf.name)
1356+
gs3d_loaded, training_info = GaussianSplat3d.from_ply(tf.name, device=self.device)
13571357

13581358
self.assertTrue(torch.allclose(gs3d_loaded.means, self.gs3d.means))
13591359
self.assertTrue(torch.allclose(gs3d_loaded.quats, self.gs3d.quats))
@@ -1400,10 +1400,10 @@ def test_gaussian_projection(self):
14001400
torch.save(conics, "regression_conics.pt")
14011401

14021402
# Regression test
1403-
test_radii = torch.load(self.data_path / "regression_radii.pt", weights_only=True)
1404-
test_means2d = torch.load(self.data_path / "regression_means2d.pt", weights_only=True)
1405-
test_depths = torch.load(self.data_path / "regression_depths.pt", weights_only=True)
1406-
test_conics = torch.load(self.data_path / "regression_conics.pt", weights_only=True)
1403+
test_radii = torch.load(self.data_path / "regression_radii.pt", map_location=self.device, weights_only=True)
1404+
test_means2d = torch.load(self.data_path / "regression_means2d.pt", map_location=self.device, weights_only=True)
1405+
test_depths = torch.load(self.data_path / "regression_depths.pt", map_location=self.device, weights_only=True)
1406+
test_conics = torch.load(self.data_path / "regression_conics.pt", map_location=self.device, weights_only=True)
14071407

14081408
visible = (radii > 0).all(dim=-1)
14091409
torch.testing.assert_close(radii, test_radii)

0 commit comments

Comments
 (0)