mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 03:42:50 +08:00
Summary: Applies new import merging and sorting from µsort v1.0. When merging imports, µsort will make a best-effort to move associated comments to match merged elements, but there are known limitations due to the diynamic nature of Python and developer tooling. These changes should not produce any dangerous runtime changes, but may require touch-ups to satisfy linters and other tooling. Note that µsort uses case-insensitive, lexicographical sorting, which results in a different ordering compared to isort. This provides a more consistent sorting order, matching the case-insensitive order used when sorting import statements by module name, and ensures that "frog", "FROG", and "Frog" always sort next to each other. For details on µsort's sorting and merging semantics, see the user guide: https://usort.readthedocs.io/en/stable/guide.html#sorting Reviewed By: bottler Differential Revision: D35553814 fbshipit-source-id: be49bdb6a4c25264ff8d4db3a601f18736d17be1
49 lines
1.5 KiB
Python
49 lines
1.5 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 os
|
|
import unittest
|
|
|
|
import torch
|
|
from pytorch3d.implicitron.tools.eval_video_trajectory import (
|
|
generate_eval_video_cameras,
|
|
)
|
|
from pytorch3d.renderer.cameras import look_at_view_transform, PerspectiveCameras
|
|
from pytorch3d.transforms import axis_angle_to_matrix
|
|
|
|
|
|
if os.environ.get("FB_TEST", False):
|
|
from common_testing import TestCaseMixin
|
|
else:
|
|
from tests.common_testing import TestCaseMixin
|
|
|
|
|
|
class TestEvalCameras(TestCaseMixin, unittest.TestCase):
|
|
def setUp(self):
|
|
torch.manual_seed(42)
|
|
|
|
def test_circular(self):
|
|
n_train_cameras = 10
|
|
n_test_cameras = 100
|
|
R, T = look_at_view_transform(azim=torch.rand(n_train_cameras) * 360)
|
|
amplitude = 0.01
|
|
R_jiggled = torch.bmm(
|
|
R, axis_angle_to_matrix(torch.rand(n_train_cameras, 3) * amplitude)
|
|
)
|
|
cameras_train = PerspectiveCameras(R=R_jiggled, T=T)
|
|
cameras_test = generate_eval_video_cameras(
|
|
cameras_train, trajectory_type="circular_lsq_fit", trajectory_scale=1.0
|
|
)
|
|
|
|
positions_test = cameras_test.get_camera_center()
|
|
center = positions_test.mean(0)
|
|
self.assertClose(center, torch.zeros(3), atol=0.1)
|
|
self.assertClose(
|
|
(positions_test - center).norm(dim=[1]),
|
|
torch.ones(n_test_cameras),
|
|
atol=0.1,
|
|
)
|