mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-20 22:56:03 +08:00
Add spherical harmoincs
This commit is contained in:
1 parent
97c9fe2541
commit
cd6342733b
7 files changed
+353
-3
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Encoding Tests
|
||||
"""
|
||||
from multiprocessing.sharedctypes import Value
|
||||
import pytest
|
||||
import torch
|
||||
from mattport.nerf.field_modules import encoding
|
||||
@@ -111,9 +112,28 @@ def test_tensor_cp_encoder():
|
||||
encoder.upsample_grid(resolution=64)
|
||||
|
||||
|
||||
def test_tensor_sh_encoder():
|
||||
"""Test Spherical Harmonic encoder"""
|
||||
|
||||
levels = 4
|
||||
out_dim = levels**2
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
encoder = encoding.SHEncoding(levels=5)
|
||||
|
||||
encoder = encoding.SHEncoding(levels=levels)
|
||||
assert encoder.get_out_dim() == out_dim
|
||||
|
||||
in_tensor = torch.zeros((10, 3))
|
||||
in_tensor[..., 1] = 1
|
||||
encoded = encoder.encode(in_tensor)
|
||||
assert encoded.shape == (10, out_dim)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_scaling_and_offset()
|
||||
test_nerf_encoder()
|
||||
test_rff_encoder()
|
||||
test_tensor_vm_encoder()
|
||||
test_tensor_cp_encoder()
|
||||
test_tensor_sh_encoder()
|
||||
@@ -23,8 +23,56 @@ def test_rgb_renderer():
|
||||
out = rgb_renderer(rgb=rgb * 0, weights=weights)
|
||||
assert torch.max(out.rgb) == pytest.approx(0)
|
||||
|
||||
# TODO Tancik: Add more precise tests
|
||||
|
||||
def test_sh_renderer():
|
||||
"""Test SH volumetric rendering"""
|
||||
|
||||
levels = 4
|
||||
num_samples = 10
|
||||
|
||||
sh = torch.ones((3, num_samples, 3 * levels**2))
|
||||
weights = torch.ones((3, num_samples))
|
||||
weights /= torch.sum(weights, axis=-1, keepdim=True)
|
||||
directions = torch.zeros((3, num_samples, 3))
|
||||
directions[..., 0] = 1
|
||||
|
||||
sh_renderer = renderers.SHRenderer()
|
||||
|
||||
out = sh_renderer(sh=sh, directions=directions, weights=weights)
|
||||
assert torch.max(out.rgb) > 0.9
|
||||
|
||||
|
||||
def test_acc_renderer():
|
||||
"""Test accumulation rendering"""
|
||||
|
||||
num_samples = 10
|
||||
weights = torch.ones((3, num_samples))
|
||||
weights /= torch.sum(weights, axis=-1, keepdim=True)
|
||||
|
||||
acc_renderer = renderers.AccumulationRenderer()
|
||||
|
||||
out = acc_renderer(weights=weights)
|
||||
assert torch.max(out.accumulation) > 0.9
|
||||
|
||||
|
||||
def test_depth_renderer():
|
||||
"""Test depth rendering"""
|
||||
|
||||
num_samples = 10
|
||||
weights = torch.ones((3, num_samples))
|
||||
weights /= torch.sum(weights, axis=-1, keepdim=True)
|
||||
|
||||
ts = torch.linspace(0, 100, num_samples)
|
||||
ts = torch.stack([ts, ts, ts], dim=0)
|
||||
|
||||
depth_renderer = renderers.DepthRenderer()
|
||||
|
||||
out = depth_renderer(weights=weights, ts=ts)
|
||||
assert torch.min(out.depth) > 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_rgb_renderer()
|
||||
test_sh_renderer()
|
||||
test_acc_renderer()
|
||||
test_depth_renderer()
|
||||
Reference in new issue
Block a user