mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-21 06:40:35 +08:00
avoid running tests twice
Summary: Avoid test files explicitly importing TestCase objects from each other, because doing so causes the tests to be discovered twice by unittest discover. This means moving a few static functions out of their classes. I noticed this while trying to fix failures from yesterday. Reviewed By: nikhilaravi Differential Revision: D28194679 fbshipit-source-id: ac6e6585603bd4ef9c098cdd56891d94f8923ba6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e3624b4e9d
commit
0ca839cc32
@@ -33,41 +33,41 @@ DEBUG = False
|
||||
DATA_DIR = get_tests_dir() / "data"
|
||||
|
||||
|
||||
def init_meshes(
|
||||
num_meshes: int = 10,
|
||||
num_verts: int = 1000,
|
||||
num_faces: int = 3000,
|
||||
device: str = "cpu",
|
||||
add_texture: bool = False,
|
||||
):
|
||||
device = torch.device(device)
|
||||
verts_list = []
|
||||
faces_list = []
|
||||
texts_list = []
|
||||
for _ in range(num_meshes):
|
||||
verts = torch.rand((num_verts, 3), dtype=torch.float32, device=device)
|
||||
faces = torch.randint(
|
||||
num_verts, size=(num_faces, 3), dtype=torch.int64, device=device
|
||||
)
|
||||
texts = torch.rand((num_verts, 3), dtype=torch.float32, device=device)
|
||||
verts_list.append(verts)
|
||||
faces_list.append(faces)
|
||||
texts_list.append(texts)
|
||||
|
||||
# create textures
|
||||
textures = None
|
||||
if add_texture:
|
||||
textures = TexturesVertex(texts_list)
|
||||
meshes = Meshes(verts=verts_list, faces=faces_list, textures=textures)
|
||||
|
||||
return meshes
|
||||
|
||||
|
||||
class TestSamplePoints(TestCaseMixin, unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
torch.manual_seed(1)
|
||||
|
||||
@staticmethod
|
||||
def init_meshes(
|
||||
num_meshes: int = 10,
|
||||
num_verts: int = 1000,
|
||||
num_faces: int = 3000,
|
||||
device: str = "cpu",
|
||||
add_texture: bool = False,
|
||||
):
|
||||
device = torch.device(device)
|
||||
verts_list = []
|
||||
faces_list = []
|
||||
texts_list = []
|
||||
for _ in range(num_meshes):
|
||||
verts = torch.rand((num_verts, 3), dtype=torch.float32, device=device)
|
||||
faces = torch.randint(
|
||||
num_verts, size=(num_faces, 3), dtype=torch.int64, device=device
|
||||
)
|
||||
texts = torch.rand((num_verts, 3), dtype=torch.float32, device=device)
|
||||
verts_list.append(verts)
|
||||
faces_list.append(faces)
|
||||
texts_list.append(texts)
|
||||
|
||||
# create textures
|
||||
textures = None
|
||||
if add_texture:
|
||||
textures = TexturesVertex(texts_list)
|
||||
meshes = Meshes(verts=verts_list, faces=faces_list, textures=textures)
|
||||
|
||||
return meshes
|
||||
|
||||
def test_all_empty_meshes(self):
|
||||
"""
|
||||
Check sample_points_from_meshes raises an exception if all meshes are
|
||||
@@ -298,9 +298,7 @@ class TestSamplePoints(TestCaseMixin, unittest.TestCase):
|
||||
def test_outputs(self):
|
||||
|
||||
for add_texture in (True, False):
|
||||
meshes = TestSamplePoints.init_meshes(
|
||||
device=torch.device("cuda:0"), add_texture=add_texture
|
||||
)
|
||||
meshes = init_meshes(device=torch.device("cuda:0"), add_texture=add_texture)
|
||||
out1 = sample_points_from_meshes(meshes, num_samples=100)
|
||||
self.assertTrue(torch.is_tensor(out1))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user