mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-20 14:20:38 +08:00
test fixes and lints
Summary: - followup recent pyre change D63415925 - make tests remove temporary files - weights_only=True in torch.load - lint fixes 3 test fixes from VRehnberg in https://github.com/facebookresearch/pytorch3d/issues/1914 - imageio channels fix - frozen decorator in test_config - load_blobs positional Reviewed By: MichaelRamamonjisoa Differential Revision: D66162167 fbshipit-source-id: 7737e174691b62f1708443a4fae07343cec5bfeb
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c17e6f947a
commit
e20cbe9b0e
@@ -246,7 +246,7 @@ class TestConfig(unittest.TestCase):
|
||||
|
||||
enable_get_default_args(Foo)
|
||||
|
||||
@dataclass()
|
||||
@dataclass(frozen=True)
|
||||
class Bar:
|
||||
aa: int = 9
|
||||
bb: int = 9
|
||||
|
||||
@@ -87,7 +87,9 @@ class CanineFrameDataBuilder(
|
||||
sequence_annotation: types.SequenceAnnotation,
|
||||
load_blobs: bool = True,
|
||||
) -> CanineFrameData:
|
||||
frame_data = super().build(frame_annotation, sequence_annotation, load_blobs)
|
||||
frame_data = super().build(
|
||||
frame_annotation, sequence_annotation, load_blobs=load_blobs
|
||||
)
|
||||
frame_data.num_dogs = frame_annotation.num_dogs or 101
|
||||
frame_data.magnetic_field_average_flux_density = (
|
||||
frame_annotation.magnetic_field.average_flux_density
|
||||
|
||||
@@ -76,7 +76,7 @@ class TestForward(unittest.TestCase):
|
||||
"test_out",
|
||||
"test_forward_TestForward_test_bg_weight_hits.png",
|
||||
),
|
||||
(hits * 255.0).cpu().to(torch.uint8).numpy(),
|
||||
(hits * 255.0).cpu().to(torch.uint8).squeeze(2).numpy(),
|
||||
)
|
||||
self.assertEqual(hits[500, 500, 0].item(), 1.0)
|
||||
self.assertTrue(
|
||||
@@ -139,7 +139,7 @@ class TestForward(unittest.TestCase):
|
||||
"test_out",
|
||||
"test_forward_TestForward_test_basic_3chan_hits.png",
|
||||
),
|
||||
(hits * 255.0).cpu().to(torch.uint8).numpy(),
|
||||
(hits * 255.0).cpu().to(torch.uint8).squeeze(2).numpy(),
|
||||
)
|
||||
self.assertEqual(hits[500, 500, 0].item(), 1.0)
|
||||
self.assertTrue(
|
||||
@@ -194,7 +194,7 @@ class TestForward(unittest.TestCase):
|
||||
"test_out",
|
||||
"test_forward_TestForward_test_basic_1chan.png",
|
||||
),
|
||||
(result * 255.0).cpu().to(torch.uint8).numpy(),
|
||||
(result * 255.0).cpu().to(torch.uint8).squeeze(2).numpy(),
|
||||
)
|
||||
imageio.imsave(
|
||||
path.join(
|
||||
@@ -202,7 +202,7 @@ class TestForward(unittest.TestCase):
|
||||
"test_out",
|
||||
"test_forward_TestForward_test_basic_1chan_hits.png",
|
||||
),
|
||||
(hits * 255.0).cpu().to(torch.uint8).numpy(),
|
||||
(hits * 255.0).cpu().to(torch.uint8).squeeze(2).numpy(),
|
||||
)
|
||||
self.assertEqual(hits[500, 500, 0].item(), 1.0)
|
||||
self.assertTrue(
|
||||
@@ -264,7 +264,7 @@ class TestForward(unittest.TestCase):
|
||||
"test_out",
|
||||
"test_forward_TestForward_test_basic_8chan_hits.png",
|
||||
),
|
||||
(hits * 255.0).cpu().to(torch.uint8).numpy(),
|
||||
(hits * 255.0).cpu().to(torch.uint8).squeeze(2).numpy(),
|
||||
)
|
||||
self.assertEqual(hits[500, 500, 0].item(), 1.0)
|
||||
self.assertTrue(
|
||||
|
||||
@@ -43,7 +43,7 @@ class TestBuild(unittest.TestCase):
|
||||
tutorials = sorted(tutorials_dir.glob("*.ipynb"))
|
||||
|
||||
for tutorial in tutorials:
|
||||
with open(tutorial) as f:
|
||||
with open(tutorial, encoding="utf8") as f:
|
||||
json.load(f)
|
||||
|
||||
@unittest.skipIf(in_conda_build or in_re_worker, "In conda build, or RE worker")
|
||||
|
||||
@@ -53,7 +53,7 @@ def _write(mesh, path, **kwargs) -> None:
|
||||
io.save_mesh(mesh, path, **kwargs)
|
||||
|
||||
with open(path, "rb") as f:
|
||||
_, stored_length = _read_header(f)
|
||||
_, stored_length = _read_header(f) # pyre-ignore
|
||||
assert stored_length == os.path.getsize(path)
|
||||
|
||||
|
||||
@@ -191,14 +191,14 @@ class TestMeshGltfIO(TestCaseMixin, unittest.TestCase):
|
||||
mesh = _load(glb, device=device)
|
||||
|
||||
# save the mesh to a glb file
|
||||
glb = DATA_DIR / "cow_write.glb"
|
||||
_write(mesh, glb)
|
||||
glb_reload = DATA_DIR / "cow_write.glb"
|
||||
_write(mesh, glb_reload)
|
||||
|
||||
# load again
|
||||
glb_reload = DATA_DIR / "cow_write.glb"
|
||||
self.assertTrue(glb_reload.is_file())
|
||||
device = torch.device("cuda:0")
|
||||
mesh_reload = _load(glb_reload, device=device)
|
||||
glb_reload.unlink()
|
||||
|
||||
# assertions
|
||||
self.assertEqual(mesh_reload.faces_packed().shape, (5856, 3))
|
||||
@@ -232,6 +232,7 @@ class TestMeshGltfIO(TestCaseMixin, unittest.TestCase):
|
||||
# reload the ico_sphere
|
||||
device = torch.device("cuda:0")
|
||||
mesh_reload = _load(glb, device=device, include_textures=False)
|
||||
glb.unlink()
|
||||
|
||||
self.assertClose(
|
||||
ico_sphere_mesh.verts_padded().cpu(),
|
||||
@@ -299,9 +300,9 @@ class TestMeshGltfIO(TestCaseMixin, unittest.TestCase):
|
||||
_write(mesh, glb)
|
||||
|
||||
# reload the mesh glb file saved in TexturesVertex format
|
||||
glb = DATA_DIR / "cow_write_texturesvertex.glb"
|
||||
self.assertTrue(glb.is_file())
|
||||
mesh_dash = _load(glb, device=device)
|
||||
glb.unlink()
|
||||
self.assertEqual(len(mesh_dash), 1)
|
||||
|
||||
self.assertEqual(mesh_dash.faces_packed().shape, (5856, 3))
|
||||
@@ -381,3 +382,4 @@ class TestMeshGltfIO(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
glb = DATA_DIR / "example_write_texturesvertex.glb"
|
||||
_write(mesh, glb)
|
||||
glb.unlink()
|
||||
|
||||
@@ -196,7 +196,7 @@ class TestPointsToVolumes(TestCaseMixin, unittest.TestCase):
|
||||
Generate a batch of `batch_size` cube meshes.
|
||||
"""
|
||||
|
||||
device = torch.device(device)
|
||||
device_ = torch.device(device)
|
||||
|
||||
verts, faces = [], []
|
||||
|
||||
@@ -213,7 +213,7 @@ class TestPointsToVolumes(TestCaseMixin, unittest.TestCase):
|
||||
[0.0, 0.0, 1.0],
|
||||
],
|
||||
dtype=torch.float32,
|
||||
device=device,
|
||||
device=device_,
|
||||
)
|
||||
verts.append(v)
|
||||
faces.append(
|
||||
@@ -233,7 +233,7 @@ class TestPointsToVolumes(TestCaseMixin, unittest.TestCase):
|
||||
[0, 1, 6],
|
||||
],
|
||||
dtype=torch.int64,
|
||||
device=device,
|
||||
device=device_,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -316,7 +316,7 @@ class TestPointsToVolumes(TestCaseMixin, unittest.TestCase):
|
||||
outfile = (
|
||||
outdir
|
||||
+ f"/rgb_{interp_mode}"
|
||||
+ f"_{str(volume_size).replace(' ','')}"
|
||||
+ f"_{str(volume_size).replace(' ', '')}"
|
||||
+ f"_{vidx:003d}_sldim{slice_dim}.png"
|
||||
)
|
||||
im.save(outfile)
|
||||
|
||||
@@ -639,4 +639,4 @@ class TestRaysampling(TestCaseMixin, unittest.TestCase):
|
||||
origin1, origin2, rtol=1e-4, atol=1e-4
|
||||
) == (id1 == id2), (origin1, origin2, id1, id2)
|
||||
assert not torch.allclose(dir1, dir2), (dir1, dir2)
|
||||
self.assertClose(len1, len2), (len1, len2)
|
||||
self.assertClose(len1, len2)
|
||||
|
||||
@@ -689,7 +689,7 @@ class TestRenderVolumes(TestCaseMixin, unittest.TestCase):
|
||||
outfile = (
|
||||
outdir
|
||||
+ f"/rgb_{sample_mode}"
|
||||
+ f"_{str(volume_size).replace(' ','')}"
|
||||
+ f"_{str(volume_size).replace(' ', '')}"
|
||||
+ f"_{imidx:003d}"
|
||||
)
|
||||
if image_ is image:
|
||||
|
||||
Reference in New Issue
Block a user