예제 #1
0
    def test_copyright(self):
        test_dir = get_tests_dir()
        root_dir = test_dir.parent

        extensions = ("py", "cu", "cuh", "cpp", "h", "hpp", "sh")

        expect = ("Copyright (c) Facebook, Inc. and its affiliates." +
                  " All rights reserved.\n")

        files_missing_copyright_header = []

        for extension in extensions:
            for path in root_dir.glob(f"**/*.{extension}"):
                if str(path).endswith(
                        "pytorch3d/transforms/external/kornia_angle_axis_to_rotation_matrix.py"
                ):
                    continue
                if str(path).endswith(
                        "pytorch3d/csrc/pulsar/include/fastermath.h"):
                    continue
                with open(path) as f:
                    firstline = f.readline()
                    if firstline.startswith(("# -*-", "#!")):
                        firstline = f.readline()
                    if not firstline.endswith(expect):
                        files_missing_copyright_header.append(str(path))

        if len(files_missing_copyright_header) != 0:
            self.fail("\n".join(files_missing_copyright_header))
예제 #2
0
    def test_name_clash(self):
        # For setup.py, all translation units need distinct names, so we
        # cannot have foo.cu and foo.cpp, even in different directories.
        test_dir = get_tests_dir()
        source_dir = test_dir.parent / "pytorch3d"

        stems = []
        for extension in [".cu", ".cpp"]:
            files = source_dir.glob(f"**/*{extension}")
            stems.extend(f.stem for f in files)

        counter = Counter(stems)
        for k, v in counter.items():
            self.assertEqual(v, 1, f"Too many files with stem {k}.")
 def test_multinomial_weights(self):
     """
     Confirm that torch.multinomial does not sample elements which have
     zero probability using a real example of input from a training run.
     """
     weights = torch.load(get_tests_dir() / "weights.pt")
     S = 4096
     num_trials = 100
     for _ in range(0, num_trials):
         weights[weights < 0] = 0.0
         samples = weights.multinomial(S, replacement=True)
         sampled_weights = weights[samples]
         assert sampled_weights.min() > 0
         if sampled_weights.min() <= 0:
             return False
     return True
from pytorch3d.renderer import TexturesVertex
from pytorch3d.renderer.cameras import FoVPerspectiveCameras, look_at_view_transform
from pytorch3d.renderer.mesh.rasterize_meshes import barycentric_coordinates
from pytorch3d.renderer.points import (
    NormWeightedCompositor,
    PointsRasterizationSettings,
    PointsRasterizer,
    PointsRenderer,
)
from pytorch3d.structures import Meshes, Pointclouds
from pytorch3d.utils.ico_sphere import ico_sphere

# If DEBUG=True, save out images generated in the tests for debugging.
# All saved images have prefix DEBUG_
DEBUG = False
DATA_DIR = get_tests_dir() / "data"


class TestSamplePoints(TestCaseMixin, unittest.TestCase):
    def setUp(self) -> None:
        super().setUp()
        torch.manual_seed(1)

    @staticmethod
    def init_meshes(
        num_meshes: int = 10,
        num_verts: int = 1000,
        num_faces: int = 3000,
        device: str = "cpu",
        add_texture: bool = False,
    ):
 def setUp(self) -> None:
     super().setUp()
     torch.manual_seed(42)
     np.random.seed(42)
     trimesh_results_path = get_tests_dir() / "data/icp_data.pth"
     self.trimesh_results = torch.load(trimesh_results_path)
예제 #6
0
from pytorch3d.implicitron.models.view_pooling.feature_aggregation import (
    AngleWeightedIdentityFeatureAggregator,
    AngleWeightedReductionFeatureAggregator,
)
from pytorch3d.implicitron.tools.config import (
    get_default_args,
    remove_unused_components,
)


if os.environ.get("FB_TEST", False):
    from common_testing import get_tests_dir
else:
    from tests.common_testing import get_tests_dir

DATA_DIR = get_tests_dir() / "implicitron/data"
DEBUG: bool = False

# Tests the use of the config system in implicitron


class TestGenericModel(unittest.TestCase):
    def setUp(self):
        self.maxDiff = None

    def test_create_gm(self):
        args = get_default_args(GenericModel)
        gm = GenericModel(**args)
        self.assertIsInstance(gm.renderer, MultiPassEmissionAbsorptionRenderer)
        self.assertIsInstance(
            gm.feature_aggregator, AngleWeightedReductionFeatureAggregator