mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-01 13:28:59 +08:00
Merge remote-tracking branch 'origin' into generative
This commit is contained in:
commit
978bf1d12d
73 files changed
+1862
-720
No files matched your search
@@ -0,0 +1,79 @@
|
||||
"""
|
||||
Test pipeline
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
# pylint: disable=no-self-use
|
||||
# pylint: disable=missing-class-docstring
|
||||
# pylint: disable=unused-argument
|
||||
# pylint: disable=abstract-method
|
||||
import torch
|
||||
from torch import nn
|
||||
|
||||
from nerfstudio.cameras.cameras import Cameras
|
||||
from nerfstudio.data.datasets.base_dataset import DataparserOutputs, InputDataset
|
||||
from nerfstudio.pipelines.base_pipeline import (
|
||||
Model,
|
||||
ModelConfig,
|
||||
VanillaDataManagerConfig,
|
||||
VanillaPipeline,
|
||||
VanillaPipelineConfig,
|
||||
)
|
||||
|
||||
|
||||
class MockedDataManager:
|
||||
"""Mocked data manager"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
num_images = 0
|
||||
self.train_dataset = InputDataset(
|
||||
DataparserOutputs(
|
||||
image_filenames=[Path("filename.png")] * num_images,
|
||||
cameras=Cameras(
|
||||
camera_to_worlds=torch.ones([num_images, 3, 4], dtype=torch.float32),
|
||||
fx=1.0,
|
||||
fy=1.0,
|
||||
cx=1.0,
|
||||
cy=1.0,
|
||||
width=2,
|
||||
height=2,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
def to(self, *args, **kwargs):
|
||||
"Mocked to"
|
||||
return self
|
||||
|
||||
|
||||
def test_load_state_dict():
|
||||
"""Test pipeline load_state_dict calls model's load_state_dict"""
|
||||
was_called = False
|
||||
|
||||
class MockedModel(Model): #
|
||||
"""Mocked model"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.register_parameter("param", nn.Parameter(torch.ones((3,))))
|
||||
|
||||
def load_state_dict(self, state_dict, strict=True):
|
||||
"""Mocked load_state_dict"""
|
||||
nonlocal was_called
|
||||
was_called = True
|
||||
assert strict
|
||||
assert "param" in state_dict
|
||||
|
||||
config = VanillaPipelineConfig(
|
||||
datamanager=VanillaDataManagerConfig(
|
||||
_target=MockedDataManager,
|
||||
),
|
||||
model=ModelConfig(_target=MockedModel),
|
||||
)
|
||||
pipeline = VanillaPipeline(config, "cpu")
|
||||
state_dict = pipeline.state_dict()
|
||||
state_dict["_model.param"].mul_(2) # pylint: disable=unsubscriptable-object
|
||||
pipeline.load_pipeline(state_dict, 0)
|
||||
assert was_called
|
||||
assert pipeline.model.param[0].item() == 2
|
||||
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
Test misc data utils
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
from pyquaternion import Quaternion
|
||||
from scipy.spatial.transform import Rotation
|
||||
|
||||
# TODO(1480) use pycolmap instead of colmap_parsing_utils
|
||||
# import pycolmap
|
||||
from nerfstudio.data.utils.colmap_parsing_utils import qvec2rotmat
|
||||
|
||||
|
||||
def test_scalar_first_scalar_last_quaternions():
|
||||
"""Many nerfstudio datasets use quaternions for pose rotations. Some use
|
||||
scalar-first format and others use scalar-last. However internally
|
||||
nerfstudio uses rotation *matrices* / projection matrices. This test
|
||||
helps document differences in quaternion encodings & conversion to
|
||||
rotation matrices.
|
||||
|
||||
FMI see call sites in nerfstudio where the various libraries are used. You
|
||||
might also consult this detailed reference:
|
||||
* "Why and How to Avoid the Flipped Quaternion Multiplication"
|
||||
Sommer et al.
|
||||
https://arxiv.org/abs/1801.07478
|
||||
"""
|
||||
|
||||
# Pick an arbitrary euler rotation; note that different communities
|
||||
# also use different rotation axes (e.g. Euler vs Tait-Bryan ...)
|
||||
rot = Rotation.from_euler("xyz", np.array([10.0, 20.0, 30.0]), degrees=True)
|
||||
|
||||
# scalar-last
|
||||
xyzw = rot.as_quat()
|
||||
assert np.allclose(xyzw, np.array([0.03813458, 0.18930786, 0.23929834, 0.95154852]))
|
||||
|
||||
# scalar-first
|
||||
wxyz = xyzw[[3, 0, 1, 2]]
|
||||
assert np.allclose(wxyz, np.array([0.95154852, 0.03813458, 0.18930786, 0.23929834]))
|
||||
|
||||
# Expected Rotation matrix
|
||||
# fmt: off
|
||||
R_expected = np.array( # pylint: disable=invalid-name
|
||||
[
|
||||
[ 0.81379768, -0.44096961, 0.37852231],
|
||||
[ 0.46984631, 0.88256412, 0.01802831],
|
||||
[-0.34202014, 0.16317591, 0.92541658]
|
||||
]
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
# Record3D / scipy
|
||||
R = Rotation.from_quat(xyzw).as_matrix()
|
||||
assert np.allclose(R, R_expected)
|
||||
|
||||
# Nuscenes / pyquaternion
|
||||
R = Quaternion(wxyz).rotation_matrix
|
||||
assert np.allclose(R, R_expected)
|
||||
|
||||
# COLMAP
|
||||
# TODO(1480) use pycolmap
|
||||
# R = pycolmap.qvec_to_rotmat(wxyz)
|
||||
R = qvec2rotmat(wxyz)
|
||||
assert np.allclose(R, R_expected)
|
||||
@@ -21,6 +21,7 @@ BLACKLIST = [
|
||||
"instant-ngp",
|
||||
"instant-ngp-bounded",
|
||||
"nerfacto",
|
||||
"volinga",
|
||||
"phototourism",
|
||||
"depth-nerfacto",
|
||||
"nerfplayer-ngp",
|
||||
|
||||
@@ -5,11 +5,11 @@ import importlib
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
from distutils.util import strtobool
|
||||
|
||||
import torch
|
||||
|
||||
from nerfstudio.utils.math import intersect_aabb
|
||||
from nerfstudio.utils.misc import strtobool
|
||||
|
||||
test_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
|
||||
|
||||
Reference in new issue
Block a user