mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-29 04:20:10 +08:00
dataloader logic, new folder structure, flatter configs (#26)
* renaming dataloader to data. adding some dataloader classes * restructuring configs * fixed instant ngp tcnn direction rescaling * working through test cases * black and lint and tests
This commit is contained in:
1 parent
24c1c77ef1
commit
457788d689
105 files changed
+8828
-682
No files matched your search
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
Code to test the occupancy grid.
|
||||
"""
|
||||
|
||||
import torch
|
||||
from pyrad.fields.occupancy_fields.occupancy_grid import OccupancyGrid
|
||||
|
||||
|
||||
def test_occupancy_grid():
|
||||
"""For testing the occupancy grid."""
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
num_cascades = 1
|
||||
resolution = 128
|
||||
aabb = torch.tensor([[-1, -1, -1], [1, 1, 1]], dtype=torch.float32).to(device)
|
||||
grid = OccupancyGrid(num_cascades, resolution, aabb)
|
||||
grid.to(device)
|
||||
density_fn = lambda x: x[..., 0:1] # xyz (..., 3) => density (...,)
|
||||
grid.update_occupancy_grid(density_fn=density_fn)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_occupancy_grid()
|
||||
@@ -0,0 +1,59 @@
|
||||
"""
|
||||
Test samplers
|
||||
"""
|
||||
import torch
|
||||
from pyrad.graphs.modules.ray_sampler import PDFSampler, UniformSampler
|
||||
|
||||
from pyrad.cameras.rays import RayBundle
|
||||
from pyrad.graphs.modules.scene_colliders import NearFarCollider
|
||||
|
||||
|
||||
def test_uniform_sampler():
|
||||
"""Test uniform sampler"""
|
||||
near_plane = 2
|
||||
far_plane = 4
|
||||
num_samples = 15
|
||||
sampler = UniformSampler(num_samples=num_samples)
|
||||
|
||||
origins = torch.zeros((10, 3))
|
||||
directions = torch.ones_like(origins)
|
||||
radius = torch.ones((10, 1))
|
||||
ray_bundle = RayBundle(origins=origins, directions=directions, pixel_area=radius)
|
||||
collider = NearFarCollider(near_plane, far_plane)
|
||||
ray_bundle = collider(ray_bundle)
|
||||
|
||||
ray_samples = sampler(ray_bundle)
|
||||
|
||||
assert ray_samples.frustums.get_positions().shape[-2] == num_samples
|
||||
|
||||
# TODO Tancik: Add more precise tests
|
||||
|
||||
|
||||
def test_pdf_sampler():
|
||||
"""Test pdf sampler"""
|
||||
near_plane = 2
|
||||
far_plane = 4
|
||||
num_samples = 15
|
||||
|
||||
origins = torch.zeros((10, 3))
|
||||
directions = torch.ones_like(origins)
|
||||
radius = torch.ones((10, 1))
|
||||
ray_bundle = RayBundle(origins=origins, directions=directions, pixel_area=radius)
|
||||
collider = NearFarCollider(near_plane, far_plane)
|
||||
ray_bundle = collider(ray_bundle)
|
||||
|
||||
uniform_sampler = UniformSampler(num_samples=num_samples)
|
||||
coarse_ray_samples = uniform_sampler(ray_bundle)
|
||||
|
||||
weights = torch.ones((10, num_samples))
|
||||
|
||||
# Just check that it doesn't crash. Need to add some actual tests.
|
||||
pdf_sampler = PDFSampler(num_samples)
|
||||
pdf_sampler(ray_bundle, coarse_ray_samples, weights, num_samples)
|
||||
|
||||
# TODO Tancik: Add more precise tests
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_uniform_sampler()
|
||||
test_pdf_sampler()
|
||||
Reference in new issue
Block a user