align_corners and padding for TexturesUV

Summary:
Allow, and make default, align_corners=True for texture maps. Allow changing the padding_mode and set the default to be "border" which produces more logical results. Some new documentation.

The previous behavior corresponds to padding_mode="zeros" and align_corners=False.

Reviewed By: gkioxari

Differential Revision: D23268775

fbshipit-source-id: 58d6229baa591baa69705bcf97471c80ba3651de
This commit is contained in:
Jeremy Reizenstein
2020-08-25 11:26:58 -07:00
committed by Facebook GitHub Bot
parent d0cec028c7
commit e25ccab3d9
8 changed files with 104 additions and 31 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -373,10 +373,10 @@ class TestMeshes(TestCaseMixin, unittest.TestCase):
self.assertFalse(new_mesh.verts_packed().requires_grad)
self.assertClose(new_mesh.verts_packed(), mesh.verts_packed())
self.assertTrue(new_mesh.verts_padded().requires_grad == False)
self.assertFalse(new_mesh.verts_padded().requires_grad)
self.assertClose(new_mesh.verts_padded(), mesh.verts_padded())
for v, newv in zip(mesh.verts_list(), new_mesh.verts_list()):
self.assertTrue(newv.requires_grad == False)
self.assertFalse(newv.requires_grad)
self.assertClose(newv, v)
def test_laplacian_packed(self):

View File

@@ -411,11 +411,11 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
new_clouds = clouds.detach()
for cloud in new_clouds.points_list():
self.assertTrue(cloud.requires_grad == False)
self.assertFalse(cloud.requires_grad)
for normal in new_clouds.normals_list():
self.assertTrue(normal.requires_grad == False)
self.assertFalse(normal.requires_grad)
for feats in new_clouds.features_list():
self.assertTrue(feats.requires_grad == False)
self.assertFalse(feats.requires_grad)
for attrib in [
"points_packed",
@@ -425,9 +425,7 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
"normals_padded",
"features_padded",
]:
self.assertTrue(
getattr(new_clouds, attrib)().requires_grad == False
)
self.assertFalse(getattr(new_clouds, attrib)().requires_grad)
self.assertCloudsEqual(clouds, new_clouds)

View File

@@ -443,19 +443,26 @@ class TestTexturesUV(TestCaseMixin, unittest.TestCase):
dists=pix_to_face,
)
tex = TexturesUV(maps=tex_map, faces_uvs=[face_uvs], verts_uvs=[vert_uvs])
meshes = Meshes(verts=[dummy_verts], faces=[face_uvs], textures=tex)
mesh_textures = meshes.textures
texels = mesh_textures.sample_textures(fragments)
for align_corners in [True, False]:
tex = TexturesUV(
maps=tex_map,
faces_uvs=[face_uvs],
verts_uvs=[vert_uvs],
align_corners=align_corners,
)
meshes = Meshes(verts=[dummy_verts], faces=[face_uvs], textures=tex)
mesh_textures = meshes.textures
texels = mesh_textures.sample_textures(fragments)
# Expected output
pixel_uvs = interpolated_uvs * 2.0 - 1.0
pixel_uvs = pixel_uvs.view(2, 1, 1, 2)
tex_map = torch.flip(tex_map, [1])
tex_map = tex_map.permute(0, 3, 1, 2)
tex_map = torch.cat([tex_map, tex_map], dim=0)
expected_out = F.grid_sample(tex_map, pixel_uvs, align_corners=False)
self.assertTrue(torch.allclose(texels.squeeze(), expected_out.squeeze()))
# Expected output
pixel_uvs = interpolated_uvs * 2.0 - 1.0
pixel_uvs = pixel_uvs.view(2, 1, 1, 2)
tex_map_ = torch.flip(tex_map, [1]).permute(0, 3, 1, 2)
tex_map_ = torch.cat([tex_map_, tex_map_], dim=0)
expected_out = F.grid_sample(
tex_map_, pixel_uvs, align_corners=align_corners, padding_mode="border"
)
self.assertTrue(torch.allclose(texels.squeeze(), expected_out.squeeze()))
def test_textures_uv_init_fail(self):
# Maps has wrong shape