Merge branch 'main' into main

This commit is contained in:
Matthew Tancik authored and GitHub committed 2023-06-23 17:49:28 -07:00
commit f9dcb4719b
51 files changed
+1554 -2655

No files matched your search

@@ -1,49 +0,0 @@
"""
Test if temporal grid run properly (forward and backward)
"""
import torch
from nerfstudio.field_components import temporal_grid
def test_temporal_grid():
"""Test temporal grid"""
if not torch.cuda.is_available():
print("Unable to test temporal grid without GPU, since CUDA kernels involved.")
return
model = temporal_grid.TemporalGridEncoder(
temporal_dim=2,
input_dim=1,
num_levels=1,
level_dim=1,
per_level_scale=1,
base_resolution=1,
log2_hashmap_size=2,
desired_resolution=None,
gridtype="tiled",
align_corners=False,
).cuda()
random_embedding = torch.rand_like(model.embeddings)
random_embedding[:, 0] = torch.arange(8).to(model.embeddings)
model.embeddings = torch.nn.Parameter(random_embedding, requires_grad=True)
x = torch.zeros([1024, 1]).cuda()
t = torch.zeros([1024, 1]).cuda()
out = model(x, t)
weight = torch.randn_like(out)
(out * weight).sum().backward()
assert torch.all(out == 0.5)
assert model.embeddings.grad is not None
assert model.embeddings.grad.sum() - weight.sum() < 0.01
assert torch.all(model.embeddings.grad[2:, :] == 0)
assert torch.all(model.embeddings.grad[:, 1:] == 0)
# TODO: test temporal_tv_loss
# model.get_temporal_tv_loss()
# TODO: Any better way to numerically test it? Especially for the gradients.
# (maybe add some randomness and multiple cases for the testing?)
if __name__ == "__main__":
test_temporal_grid()
+1 -1
View File
@@ -11,10 +11,10 @@ from nerfstudio.data.datasets.base_dataset import DataparserOutputs, InputDatase
from nerfstudio.pipelines.base_pipeline import (
Model,
ModelConfig,
VanillaDataManagerConfig,
VanillaPipeline,
VanillaPipelineConfig,
)
from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManagerConfig
class MockedDataManager:
+1 -2
View File
@@ -24,9 +24,8 @@ BLACKLIST = [
"volinga",
"phototourism",
"depth-nerfacto",
"nerfplayer-ngp",
"nerfplayer-nerfacto",
"neus",
"generfacto",
"neus-facto",
]
+16
View File
@@ -0,0 +1,16 @@
import pytest
import torch
from nerfstudio.utils.math import components_from_spherical_harmonics
@pytest.mark.parametrize("components", list(range(1, 5 + 1)))
def test_spherical_harmonics(components):
torch.manual_seed(0)
N = 1000000
dx = torch.normal(0, 1, size=(N, 3))
dx = dx / torch.linalg.norm(dx, dim=-1, keepdim=True)
sh = components_from_spherical_harmonics(components, dx)
matrix = (sh.T @ sh) / N * 4 * torch.pi
torch.testing.assert_close(matrix, torch.eye(components**2), rtol=0, atol=1e-2)