images for debugging TexturesUV

Summary: New methods to directly plot a TexturesUV map with its used points, using PIL and matplotlib.

Reviewed By: gkioxari

Differential Revision: D23782968

fbshipit-source-id: 692970857b5be13a35a3175dc82ac03963a73555
This commit is contained in:
Jeremy Reizenstein
2020-10-27 10:08:57 -07:00
committed by Facebook GitHub Bot
parent b149bbfb3c
commit aa4cc0adbc
6 changed files with 192 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

View File

@@ -2,10 +2,13 @@
import unittest
from pathlib import Path
import numpy as np
import torch
import torch.nn.functional as F
from common_testing import TestCaseMixin
from PIL import Image
from pytorch3d.renderer.mesh.rasterizer import Fragments
from pytorch3d.renderer.mesh.textures import (
TexturesAtlas,
@@ -15,9 +18,14 @@ from pytorch3d.renderer.mesh.textures import (
pack_rectangles,
)
from pytorch3d.structures import Meshes, list_to_packed, packed_to_list
from pytorch3d.vis import texturesuv_image_PIL
from test_meshes import TestMeshes
DEBUG = False
DATA_DIR = Path(__file__).resolve().parent / "data"
def tryindex(self, index, tex, meshes, source):
tex2 = tex[index]
meshes2 = meshes[index]
@@ -471,6 +479,10 @@ class TestTexturesAtlas(TestCaseMixin, unittest.TestCase):
class TestTexturesUV(TestCaseMixin, unittest.TestCase):
def setUp(self) -> None:
super().setUp()
torch.manual_seed(42)
def test_sample_textures_uv(self):
barycentric_coords = torch.tensor(
[[0.5, 0.3, 0.2], [0.3, 0.6, 0.1]], dtype=torch.float32
@@ -821,6 +833,22 @@ class TestTexturesUV(TestCaseMixin, unittest.TestCase):
tryindex(self, index, tex, meshes, source)
tryindex(self, [2, 4], tex, meshes, source)
def test_png_debug(self):
maps = torch.rand(size=(1, 256, 128, 3)) * torch.tensor([0.8, 1, 0.8])
verts_uvs = torch.rand(size=(1, 20, 2))
faces_uvs = torch.zeros(size=(1, 0, 3), dtype=torch.int64)
tex = TexturesUV(maps=maps, faces_uvs=faces_uvs, verts_uvs=verts_uvs)
image = texturesuv_image_PIL(tex, radius=3)
image_out = np.array(image)
if DEBUG:
image.save(DATA_DIR / "texturesuv_debug_.png")
with Image.open(DATA_DIR / "texturesuv_debug.png") as image_ref_file:
image_ref = np.array(image_ref_file)
self.assertClose(image_out, image_ref)
class TestRectanglePacking(TestCaseMixin, unittest.TestCase):
def setUp(self) -> None: