mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-11 02:24:38 +08:00
* Model class done, pipeline class still needs more visualization stuffs * Renaming the BaseDataContainer to DataloaderOutputs and adding documentation * Pushing more documentation, removing some trivial functions * Updating dict typing * Removing config dicts for collider * Passing tests * Pushing shell new dataloader * Saving work, need to fix NGP model's get_loss_dict and Pipeline * V1 of the ngp pipeline should be done. Need train script and debugging * Updating with latest instant-ngp code * Syntax updates from latest ngp graph code * Linter, removing unneeded code in new NGP graph code * Style * Should be good now. Linter is happy and the code is verbatum current instant-ngp * Everything done except novel view testing code * Fixing some nitpicks * Debugging dataloader * merged master * WOP. integrating pipeline with configs and notebook demo * removing model folder * a lot of name changing from Graph to Model * in progress... changing trainer to use pipeline... broken right now * pipeline code runs * switched to val dataset * makes run_eval.py work * updated configs for pipeline change * fixing test_run_train script * fixing black and linting * fix docs * small updates to trainer Co-authored-by: Jake Austin <jake-austin@berkeley.edu>
123 lines
3.4 KiB
Python
123 lines
3.4 KiB
Python
"""
|
|
Test samplers
|
|
"""
|
|
import torch
|
|
|
|
from nerfactory.cameras.rays import RayBundle
|
|
from nerfactory.models.modules.ray_sampler import (
|
|
LinearDisparitySampler,
|
|
LogSampler,
|
|
PDFSampler,
|
|
SqrtSampler,
|
|
UniformSampler,
|
|
)
|
|
from nerfactory.models.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_lin_disp_sampler():
|
|
"""Test linear in disparity sampler"""
|
|
near_plane = 2
|
|
far_plane = 4
|
|
num_samples = 15
|
|
sampler = LinearDisparitySampler(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
|
|
|
|
|
|
def test_sqrt_sampler():
|
|
"""Test square root sampler"""
|
|
near_plane = 2
|
|
far_plane = 4
|
|
num_samples = 15
|
|
sampler = SqrtSampler(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
|
|
|
|
|
|
def test_log_sampler():
|
|
"""Test log sampler"""
|
|
near_plane = 2
|
|
far_plane = 4
|
|
num_samples = 15
|
|
sampler = LogSampler(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
|
|
|
|
|
|
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, 1))
|
|
|
|
# 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()
|