Beispiel #1
0
 def test_detach(self):
     tex = TexturesVertex(
         verts_features=torch.rand(size=(10, 100, 128), requires_grad=True))
     tex.verts_features_list()
     tex_detached = tex.detach()
     self.assertFalse(tex_detached._verts_features_padded.requires_grad)
     self.assertClose(tex_detached._verts_features_padded,
                      tex._verts_features_padded)
     for i in range(tex._N):
         self.assertClose(tex._verts_features_list[i],
                          tex_detached._verts_features_list[i])
         self.assertFalse(
             tex_detached._verts_features_list[i].requires_grad)
Beispiel #2
0
 def test_clone(self):
     tex = TexturesVertex(verts_features=torch.rand(size=(10, 100, 128)))
     tex.verts_features_list()
     tex_cloned = tex.clone()
     self.assertSeparate(tex._verts_features_padded,
                         tex_cloned._verts_features_padded)
     self.assertClose(tex._verts_features_padded,
                      tex_cloned._verts_features_padded)
     self.assertSeparate(tex.valid, tex_cloned.valid)
     self.assertTrue(tex.valid.eq(tex_cloned.valid).all())
     for i in range(tex._N):
         self.assertSeparate(tex._verts_features_list[i],
                             tex_cloned._verts_features_list[i])
         self.assertClose(tex._verts_features_list[i],
                          tex_cloned._verts_features_list[i])
Beispiel #3
0
    def test_padded_to_packed(self):
        # Case where each face in the mesh has 3 unique uv vertex indices
        # - i.e. even if a vertex is shared between multiple faces it will
        # have a unique uv coordinate for each face.
        num_verts_per_mesh = [9, 6]
        D = 10
        verts_features_list = [torch.rand(v, D) for v in num_verts_per_mesh]
        verts_features_packed = list_to_packed(verts_features_list)[0]
        verts_features_list = packed_to_list(verts_features_packed,
                                             num_verts_per_mesh)
        tex = TexturesVertex(verts_features=verts_features_list)

        # This is set inside Meshes when textures is passed as an input.
        # Here we set _num_faces_per_mesh and _num_verts_per_mesh explicity.
        tex1 = tex.clone()
        tex1._num_verts_per_mesh = num_verts_per_mesh
        verts_packed = tex1.verts_features_packed()
        verts_verts_list = tex1.verts_features_list()
        verts_padded = tex1.verts_features_padded()

        for f1, f2 in zip(verts_verts_list, verts_features_list):
            self.assertTrue((f1 == f2).all().item())

        self.assertTrue(verts_packed.shape == (sum(num_verts_per_mesh), D))
        self.assertTrue(verts_padded.shape == (2, 9, D))

        # Case where num_verts_per_mesh is not set and textures
        # are initialized with a padded tensor.
        tex2 = TexturesVertex(verts_features=verts_padded)
        verts_packed = tex2.verts_features_packed()
        verts_list = tex2.verts_features_list()

        # Packed is just flattened padded as num_verts_per_mesh
        # has not been provided.
        self.assertTrue(verts_packed.shape == (9 * 2, D))

        for i, (f1, f2) in enumerate(zip(verts_list, verts_features_list)):
            n = num_verts_per_mesh[i]
            self.assertTrue((f1[:n] == f2).all().item())