pytorch3d/tests/implicitron/test_build.py
Krzysztof Chalupka cb49550486 Add MeshRasterizerOpenGL
Summary:
Adding MeshRasterizerOpenGL, a faster alternative to MeshRasterizer. The new rasterizer follows the ideas from "Differentiable Surface Rendering via non-Differentiable Sampling".

The new rasterizer 20x faster on a 2M face mesh (try pose optimization on Nefertiti from https://www.cs.cmu.edu/~kmcrane/Projects/ModelRepository/!). The larger the mesh, the larger the speedup.

There are two main disadvantages:
* The new rasterizer works with an OpenGL backend, so requires pycuda.gl and pyopengl installed (though we avoided writing any C++ code, everything is in Python!)
* The new rasterizer is non-differentiable. However, you can still differentiate the rendering function if you use if with the new SplatterPhongShader which we recently added to PyTorch3D (see the original paper cited above).

Reviewed By: patricklabatut, jcjohnson

Differential Revision: D37698816

fbshipit-source-id: 54d120639d3cb001f096237807e54aced0acda25
2022-07-22 15:52:50 -07:00

44 lines
1.7 KiB
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
import importlib
import sys
import unittest
import unittest.mock
from tests.common_testing import get_pytorch3d_dir
# This file groups together tests which look at the code without running it.
class TestBuild(unittest.TestCase):
def test_no_import_cycles(self):
# Check each module of pytorch3d imports cleanly,
# which may fail if there are import cycles.
with unittest.mock.patch.dict(sys.modules):
for module in list(sys.modules):
# If any of pytorch3d is already imported,
# the test would be pointless.
if module.startswith("pytorch3d"):
sys.modules.pop(module, None)
root_dir = get_pytorch3d_dir() / "pytorch3d"
# Exclude opengl-related files, as Implicitron is decoupled from opengl
# components which will not work without adding a dep on pytorch3d_opengl.
for module_file in root_dir.glob("**/*.py"):
if module_file.stem in (
"__init__",
"plotly_vis",
"opengl_utils",
"rasterizer_opengl",
):
continue
relative_module = str(module_file.relative_to(root_dir))[:-3]
module = "pytorch3d." + relative_module.replace("/", ".")
with self.subTest(name=module):
with unittest.mock.patch.dict(sys.modules):
importlib.import_module(module)