mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-12 10:55:57 +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>
528 KiB
528 KiB
In [5]:
# COLLAPSED
import torch
from nerfactory.cameras.rays import RayBundle
from nerfactory.models.modules import ray_sampler
import plotly.graph_objects as go
from plotly.subplots import make_subplots
num_samples = 1000
near = 2
far = 5
train_stratified = False
samplers = [
ray_sampler.UniformSampler,
ray_sampler.LinearDisparitySampler,
ray_sampler.SqrtSampler,
ray_sampler.LogSampler,
]
fig = make_subplots(
rows=2,
cols=2,
subplot_titles=("Uniform", "Linear in Disparity", "Square Root", "Log Sampler"),
shared_xaxes=True,
shared_yaxes=True,
vertical_spacing=0.1,
)
for i, Sampler in enumerate(samplers):
sampler = Sampler(num_samples=num_samples, train_stratified=train_stratified)
ray_bundle = RayBundle(
origins=torch.ones([1, 3]),
directions=torch.ones([1, 3]),
pixel_area=torch.ones([1, 1]),
nears=torch.ones([1, 1]) * near,
fars=torch.ones([1, 1]) * far,
)
samples = sampler.generate_ray_samples(ray_bundle)
trace = go.Histogram(x=samples.frustums.starts[0, :, 0], nbinsx=50)
fig.append_trace(trace, i // 2 + 1, i % 2 + 1)
fig.update_yaxes(title_text="# Samples", row=1, col=1)
fig.update_yaxes(title_text="# Samples", row=2, col=1)
fig.update_xaxes(title_text="Distance", row=2, col=1)
fig.update_xaxes(title_text="Distance", row=2, col=2)
# Overlay both histograms
fig.update_layout(height=700, hovermode=False, showlegend=False, margin=dict(l=20, r=20, t=50, b=20))
fig.update_yaxes(range=[0, 80])
fig.update_traces(opacity=0.7)
fig.show()In [6]:
# COLLAPSED
import torch
from nerfactory.cameras.rays import RayBundle
from nerfactory.models.modules import ray_sampler
import plotly.graph_objects as go
from plotly.subplots import make_subplots
num_coarse_samples = 20
num_samples = 1000
near = 2
far = 5
train_stratified = False
fig = make_subplots(
rows=1,
cols=2,
subplot_titles=("PDF", "Samples"),
)
uniform_sampler = ray_sampler.UniformSampler(num_samples=num_coarse_samples, train_stratified=train_stratified)
pdf_sampler = ray_sampler.PDFSampler(num_samples=num_samples, train_stratified=train_stratified, include_original=False)
ray_bundle = RayBundle(
origins=torch.ones([1, 3]),
directions=torch.ones([1, 3]),
pixel_area=torch.ones([1, 1]),
nears=torch.ones([1, 1]) * near,
fars=torch.ones([1, 1]) * far,
)
coarse_ray_samples = uniform_sampler(ray_bundle)
# Generate arbitrary PDF
weights = torch.ones(num_coarse_samples)
weights += torch.sin(torch.linspace(0, 3 * torch.pi, num_coarse_samples))
weights += torch.sin(torch.linspace(0, 0.5 * torch.pi, num_coarse_samples))
weights -= torch.min(weights)
weights /= torch.sum(weights)
samples = pdf_sampler.generate_ray_samples(ray_bundle, coarse_ray_samples, weights[None, :, None], num_samples)
# Plotting stuff
x = torch.ones((num_coarse_samples * 2))
x[::2] = coarse_ray_samples.frustums.starts[0, :, 0]
x[1::2] = coarse_ray_samples.frustums.ends[0, :, 0]
y = torch.ones((num_coarse_samples * 2))
y[::2] = weights
y[1::2] = weights
pdf_trace = go.Scatter(x=x, y=y)
fig.append_trace(pdf_trace, 1, 1)
samples_trace = go.Histogram(x=samples.frustums.starts[0, :, 0], nbinsx=100)
fig.append_trace(samples_trace, 1, 2)
fig.update_yaxes(title_text="# Samples", row=1, col=2)
fig.update_xaxes(title_text="Distance", row=1, col=1)
fig.update_xaxes(title_text="Distance", row=1, col=2)
# Overlay both histograms
fig.update_layout(height=400, hovermode=False, showlegend=False, margin=dict(l=20, r=20, t=50, b=20))
fig.update_traces(opacity=0.7)
fig.show()