mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 07:48:50 +08:00
Update bins
This commit is contained in:
1 parent
f2d2bde1ac
commit
201f85a175
9 files changed
+78
-53
No files matched your search
@@ -89,8 +89,11 @@ class NGPGraph(Graph):
|
||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_uniform)
|
||||
field_outputs_pdf = self.field.forward(ray_samples_pdf.to_point_samples())
|
||||
|
||||
ts, indices = torch.sort(torch.cat([ray_samples_uniform.bins, ray_samples_pdf.bins], -1), -1)
|
||||
ray_samples = ray_bundle.get_ray_samples(ts)
|
||||
# Hacky treatment of bins as points to allow us to merge uniform and pdf.
|
||||
ts_uniform = (ray_samples_uniform.bin_starts + ray_samples_uniform.bin_ends) / 2.0
|
||||
ts_pdf = (ray_samples_pdf.bin_starts + ray_samples_pdf.bin_ends) / 2.0
|
||||
ts, indices = torch.sort(torch.cat([ts_uniform, ts_pdf], -1), -1)
|
||||
ray_samples = ray_bundle.get_ray_samples(bin_starts=ts, bin_ends=ts)
|
||||
field_outputs = {}
|
||||
for fo_name, _ in field_outputs_pdf.items():
|
||||
fo_uniform = field_outputs_uniform[fo_name]
|
||||
@@ -106,11 +109,11 @@ class NGPGraph(Graph):
|
||||
weights=weights,
|
||||
)
|
||||
accumulation = self.renderer_accumulation(weights)
|
||||
depth = self.renderer_depth(weights, ray_samples.bins)
|
||||
depth = self.renderer_depth(weights, ray_samples)
|
||||
|
||||
densities_occupancy_grid = self.occupancy_grid.get_densities(ray_samples.positions)
|
||||
densities_occupancy_grid = self.occupancy_grid.get_densities(ray_samples.frustums.get_positions())
|
||||
weights_occupancy_grid = ray_samples.get_weights(densities_occupancy_grid)
|
||||
depth_occupancy_grid = self.renderer_depth(weights_occupancy_grid, ray_samples.bins)
|
||||
depth_occupancy_grid = self.renderer_depth(weights_occupancy_grid, ray_samples)
|
||||
|
||||
outputs = {
|
||||
"rgb": rgb,
|
||||
|
||||
@@ -105,7 +105,7 @@ class MipNerfGraph(Graph):
|
||||
weights=weights_coarse,
|
||||
)
|
||||
accumulation_coarse = self.renderer_accumulation(weights_coarse)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.bins)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform)
|
||||
|
||||
# pdf sampling
|
||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||
@@ -118,7 +118,7 @@ class MipNerfGraph(Graph):
|
||||
weights=weights_fine,
|
||||
)
|
||||
accumulation_fine = self.renderer_accumulation(weights_fine)
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.bins)
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf)
|
||||
|
||||
outputs = {
|
||||
"rgb_coarse": rgb_coarse,
|
||||
|
||||
@@ -109,7 +109,7 @@ class UniformSampler(Sampler):
|
||||
bin_lower = torch.cat([bins[..., :1], bin_centers], -1)
|
||||
bins = bin_lower + (bin_upper - bin_lower) * t_rand
|
||||
|
||||
ray_samples = ray_bundle.get_ray_samples(bins)
|
||||
ray_samples = ray_bundle.get_ray_samples(bin_starts=bins[..., :-1], bin_ends=bins[..., 1:])
|
||||
|
||||
return ray_samples
|
||||
|
||||
@@ -216,18 +216,28 @@ class PDFSampler(Sampler):
|
||||
x_end = torch.min(torch.where(~mask, x[..., None], x[..., -1:, None]), -2)[0]
|
||||
return x_start, x_end
|
||||
|
||||
bins_g0, bins_g1 = find_interval(mask, ray_samples.bins)
|
||||
# Force bins to not have a gap between them. Kinda hacky, should reconsider.
|
||||
existing_bins = torch.cat(
|
||||
[
|
||||
ray_samples.bin_starts[..., :1],
|
||||
(ray_samples.bin_starts[..., 1:] + ray_samples.bin_ends[..., :-1]) / 2.0,
|
||||
ray_samples.bin_ends[..., -1:],
|
||||
],
|
||||
axis=-1,
|
||||
)
|
||||
|
||||
bins_g0, bins_g1 = find_interval(mask, existing_bins)
|
||||
cdf_g0, cdf_g1 = find_interval(mask, cdf)
|
||||
|
||||
t = torch.clip(torch.nan_to_num((u - cdf_g0) / (cdf_g1 - cdf_g0), 0), 0, 1)
|
||||
bins = bins_g0 + t * (bins_g1 - bins_g0)
|
||||
|
||||
if self.include_original:
|
||||
bins, _ = torch.sort(torch.cat([ray_samples.bins, bins], -1), -1)
|
||||
bins, _ = torch.sort(torch.cat([existing_bins, bins], -1), -1)
|
||||
|
||||
# Stop gradients
|
||||
bins = bins.detach()
|
||||
|
||||
ray_samples = ray_bundle.get_ray_samples(bins)
|
||||
ray_samples = ray_bundle.get_ray_samples(bin_starts=bins[..., :-1], bin_ends=bins[..., 1:])
|
||||
|
||||
return ray_samples
|
||||
@@ -111,7 +111,7 @@ class NerfWGraph(Graph):
|
||||
rgb=field_outputs_coarse[FieldHeadNames.RGB],
|
||||
weights=weights_coarse,
|
||||
)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.bins)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform)
|
||||
|
||||
# pdf sampling
|
||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||
@@ -145,8 +145,8 @@ class NerfWGraph(Graph):
|
||||
density_transient = field_outputs_fine[FieldHeadNames.TRANSIENT_DENSITY]
|
||||
|
||||
# depth
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.bins)
|
||||
depth_fine_static = self.renderer_depth(weights_fine_static, ray_samples_pdf.bins)
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf)
|
||||
depth_fine_static = self.renderer_depth(weights_fine_static, ray_samples_pdf)
|
||||
|
||||
# uncertainty
|
||||
uncertainty = self.renderer_uncertainty(field_outputs_fine[FieldHeadNames.UNCERTAINTY], weights_fine_transient)
|
||||
|
||||
@@ -135,7 +135,7 @@ class SemanticNerfGraph(NeRFGraph):
|
||||
weights=weights_coarse,
|
||||
)
|
||||
accumulation_coarse = self.renderer_accumulation(weights_coarse)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.bins)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform)
|
||||
|
||||
# pdf sampling
|
||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||
@@ -148,7 +148,7 @@ class SemanticNerfGraph(NeRFGraph):
|
||||
weights=weights_fine,
|
||||
)
|
||||
accumulation_fine = self.renderer_accumulation(weights_fine)
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.bins)
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf)
|
||||
semantic_fine = self.renderer_semantic(field_outputs_fine[FieldHeadNames.SEMANTICS], weights=weights_fine)
|
||||
|
||||
outputs = {
|
||||
|
||||
@@ -114,7 +114,7 @@ class NeRFGraph(Graph):
|
||||
weights=weights_coarse,
|
||||
)
|
||||
accumulation_coarse = self.renderer_accumulation(weights_coarse)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform.bins)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform)
|
||||
|
||||
# pdf sampling
|
||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||
@@ -127,7 +127,7 @@ class NeRFGraph(Graph):
|
||||
weights=weights_fine,
|
||||
)
|
||||
accumulation_fine = self.renderer_accumulation(weights_fine)
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf.bins)
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf)
|
||||
|
||||
outputs = {
|
||||
"rgb_coarse": rgb_coarse,
|
||||
|
||||
Reference in new issue
Block a user