Commit 31c448a9 authored by Jeremy Reizenstein's avatar Jeremy Reizenstein Committed by Facebook GitHub Bot
Browse files

Test gltf texture without renderer.

Summary:
Change the cow gltf loading test to validate the texture values and not to validate the renderer output because it has an unstable pixel.

Also a couple of lints.

Reviewed By: patricklabatut

Differential Revision: D29131260

fbshipit-source-id: 5e11f066a2a638588aacb09776cc842173ef669f
parent 9c09c0d3
...@@ -6,6 +6,7 @@ from typing import NamedTuple, Sequence, Union ...@@ -6,6 +6,7 @@ from typing import NamedTuple, Sequence, Union
import torch import torch
from pytorch3d import _C # pyre-fixme[21]: Could not find name `_C` in `pytorch3d`. from pytorch3d import _C # pyre-fixme[21]: Could not find name `_C` in `pytorch3d`.
# Example functions for blending the top K colors per pixel using the outputs # Example functions for blending the top K colors per pixel using the outputs
# from rasterization. # from rasterization.
# NOTE: All blending function should return an RGBA image per batch element # NOTE: All blending function should return an RGBA image per batch element
......
...@@ -401,7 +401,7 @@ def pix_to_non_square_ndc(i, S1, S2): ...@@ -401,7 +401,7 @@ def pix_to_non_square_ndc(i, S1, S2):
return -offset + (ndc_range * i + offset) / S1 return -offset + (ndc_range * i + offset) / S1
def rasterize_meshes_python( def rasterize_meshes_python( # noqa: C901
meshes, meshes,
image_size: Union[int, Tuple[int, int]] = 256, image_size: Union[int, Tuple[int, int]] = 256,
blur_radius: float = 0.0, blur_radius: float = 0.0,
......
...@@ -143,14 +143,26 @@ class TestMeshGltfIO(TestCaseMixin, unittest.TestCase): ...@@ -143,14 +143,26 @@ class TestMeshGltfIO(TestCaseMixin, unittest.TestCase):
mesh_obj.get_bounding_boxes().cpu(), mesh_obj.get_bounding_boxes() mesh_obj.get_bounding_boxes().cpu(), mesh_obj.get_bounding_boxes()
) )
self.assertClose(
mesh.textures.verts_uvs_padded().cpu(), mesh_obj.textures.verts_uvs_padded()
)
self.assertClose(
mesh.textures.faces_uvs_padded().cpu(), mesh_obj.textures.faces_uvs_padded()
)
self.assertClose(
mesh.textures.maps_padded().cpu(), mesh_obj.textures.maps_padded()
)
if DEBUG: if DEBUG:
texturesuv_image_PIL(mesh.textures).save(DATA_DIR / "out_cow.png") texturesuv_image_PIL(mesh.textures).save(DATA_DIR / "out_cow.png")
image = _render(mesh, "cow", azim=4)
with Image.open(DATA_DIR / "glb_cow.png") as f: image = _render(mesh, "cow", azim=4)
expected = np.array(f) with Image.open(DATA_DIR / "glb_cow.png") as f:
expected = np.array(f)
self.assertClose(image, expected) self.assertClose(image, expected)
def test_load_cow_no_texture(self): def test_load_cow_no_texture(self):
""" """
......
...@@ -17,8 +17,8 @@ from common_testing import TestCaseMixin, get_tests_dir, load_rgb_image ...@@ -17,8 +17,8 @@ from common_testing import TestCaseMixin, get_tests_dir, load_rgb_image
from pytorch3d.io import save_obj from pytorch3d.io import save_obj
from pytorch3d.renderer.cameras import ( from pytorch3d.renderer.cameras import (
FoVPerspectiveCameras, FoVPerspectiveCameras,
look_at_view_transform,
PerspectiveCameras, PerspectiveCameras,
look_at_view_transform,
) )
from pytorch3d.renderer.lighting import PointLights from pytorch3d.renderer.lighting import PointLights
from pytorch3d.renderer.mesh import ( from pytorch3d.renderer.mesh import (
...@@ -35,6 +35,7 @@ from pytorch3d.renderer.mesh.textures import TexturesVertex ...@@ -35,6 +35,7 @@ from pytorch3d.renderer.mesh.textures import TexturesVertex
from pytorch3d.structures.meshes import Meshes from pytorch3d.structures.meshes import Meshes
from pytorch3d.utils import torus from pytorch3d.utils import torus
# If DEBUG=True, save out images generated in the tests for debugging. # If DEBUG=True, save out images generated in the tests for debugging.
# All saved images have prefix DEBUG_ # All saved images have prefix DEBUG_
DEBUG = False DEBUG = False
......
...@@ -4,10 +4,7 @@ import unittest ...@@ -4,10 +4,7 @@ import unittest
import torch import torch
from common_testing import TestCaseMixin from common_testing import TestCaseMixin
from pytorch3d.renderer.cameras import ( from pytorch3d.renderer.cameras import PerspectiveCameras, look_at_view_transform
look_at_view_transform,
PerspectiveCameras,
)
from pytorch3d.renderer.mesh.rasterizer import Fragments from pytorch3d.renderer.mesh.rasterizer import Fragments
from pytorch3d.renderer.mesh.shader import ( from pytorch3d.renderer.mesh.shader import (
HardFlatShader, HardFlatShader,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment