mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 13:59:10 +08:00
Remove redundant data (#103)
RaySamples contained fields for bin_starts and bin_ends. These are also stored in the frustums. This PR removes them from the RaySamples.
This commit is contained in:
1 parent
be45d5c9bb
commit
74280110ce
12 files changed
+145682
-145693
No files matched your search
@@ -102,8 +102,8 @@ class NGPGraph(Graph):
|
||||
field_outputs_pdf = self.field.forward(ray_samples_pdf)
|
||||
|
||||
# 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_uniform = (ray_samples_uniform.frustums.starts + ray_samples_uniform.frustums.ends) / 2.0
|
||||
ts_pdf = (ray_samples_pdf.frustums.starts + ray_samples_pdf.frustums.ends) / 2.0
|
||||
ts, indices = torch.sort(torch.cat([ts_uniform, ts_pdf], -2), -2)
|
||||
bin_starts = ts
|
||||
bin_ends = torch.cat([ts[..., 1:, :], ts[..., -1:, :]], dim=-2)
|
||||
|
||||
@@ -30,7 +30,7 @@ from pyrad.fields.modules.field_heads import FieldHeadNames
|
||||
from pyrad.fields.modules.spatial_distortions import SceneContraction
|
||||
from pyrad.fields.nerf_field import NeRFField
|
||||
from pyrad.graphs.base import Graph
|
||||
from pyrad.graphs.modules.ray_losses import interval_loss
|
||||
from pyrad.graphs.modules.ray_losses import distortion_loss
|
||||
from pyrad.optimizers.loss import MSELoss
|
||||
from pyrad.graphs.modules.ray_sampler import PDFSampler, UniformSampler
|
||||
from pyrad.renderers.renderers import AccumulationRenderer, DepthRenderer, RGBRenderer
|
||||
@@ -112,7 +112,7 @@ class MipNerf360Graph(Graph):
|
||||
)
|
||||
accumulation_coarse = self.renderer_accumulation(weights_coarse)
|
||||
depth_coarse = self.renderer_depth(weights_coarse, ray_samples_uniform)
|
||||
ray_loss_coarse = interval_loss(ray_samples_uniform, field_outputs_coarse[FieldHeadNames.DENSITY])
|
||||
ray_loss_coarse = distortion_loss(ray_samples_uniform, field_outputs_coarse[FieldHeadNames.DENSITY])
|
||||
|
||||
# pdf sampling
|
||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||
@@ -126,7 +126,7 @@ class MipNerf360Graph(Graph):
|
||||
)
|
||||
accumulation_fine = self.renderer_accumulation(weights_fine)
|
||||
depth_fine = self.renderer_depth(weights_fine, ray_samples_pdf)
|
||||
ray_loss_fine = interval_loss(ray_samples_pdf, field_outputs_fine[FieldHeadNames.DENSITY])
|
||||
ray_loss_fine = distortion_loss(ray_samples_pdf, field_outputs_fine[FieldHeadNames.DENSITY])
|
||||
|
||||
outputs = {
|
||||
"rgb_coarse": rgb_coarse,
|
||||
|
||||
@@ -20,8 +20,8 @@ from torchtyping import TensorType
|
||||
from pyrad.cameras.rays import RaySamples
|
||||
|
||||
|
||||
def interval_loss(ray_samples: RaySamples, densities: TensorType[..., "num_samples", 1]) -> TensorType[..., 1]:
|
||||
"""Interval loss origially proposed in MipNeRF-360.
|
||||
def distortion_loss(ray_samples: RaySamples, densities: TensorType[..., "num_samples", 1]) -> TensorType[..., 1]:
|
||||
"""Ray baserd distortion loss proposed in MipNeRF-360.
|
||||
|
||||
.. math::
|
||||
|
||||
@@ -36,18 +36,18 @@ def interval_loss(ray_samples: RaySamples, densities: TensorType[..., "num_sampl
|
||||
densities (TensorType[..., "num_samples", 1]): Predicted sample densities
|
||||
|
||||
Returns:
|
||||
TensorType[..., 1]: Interval Loss.
|
||||
TensorType[..., 1]: Distortion Loss.
|
||||
"""
|
||||
|
||||
# Compute the weight at each sample location
|
||||
weights = ray_samples.get_weights(densities)
|
||||
|
||||
midpoints = (ray_samples.bin_starts + ray_samples.bin_ends) / 2.0 # (..., num_samples, 1)
|
||||
midpoints = (ray_samples.frustums.starts + ray_samples.frustums.ends) / 2.0 # (..., num_samples, 1)
|
||||
|
||||
loss = (
|
||||
weights * weights[..., None, :, 0] * torch.abs(midpoints - midpoints[..., None, :, 0])
|
||||
) # (..., num_samples, num_samples)
|
||||
loss = torch.sum(loss, dim=(-1, -2))[..., None] # (..., num_samples)
|
||||
loss = loss + 1 / 3.0 * torch.sum(weights**2 * (ray_samples.bin_ends - ray_samples.bin_starts), dim=-2)
|
||||
loss = loss + 1 / 3.0 * torch.sum(weights**2 * (ray_samples.frustums.ends - ray_samples.frustums.starts), dim=-2)
|
||||
|
||||
return loss
|
||||
@@ -337,9 +337,9 @@ class PDFSampler(Sampler):
|
||||
# Force bins to not have a gap between them. Kinda hacky, should reconsider.
|
||||
existing_bins = torch.cat(
|
||||
[
|
||||
ray_samples.bin_starts[..., :1, 0],
|
||||
(ray_samples.bin_starts[..., 1:, 0] + ray_samples.bin_ends[..., :-1, 0]) / 2.0,
|
||||
ray_samples.bin_ends[..., -1:, 0],
|
||||
ray_samples.frustums.starts[..., :1, 0],
|
||||
(ray_samples.frustums.starts[..., 1:, 0] + ray_samples.frustums.ends[..., :-1, 0]) / 2.0,
|
||||
ray_samples.frustums.ends[..., -1:, 0],
|
||||
],
|
||||
axis=-1,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user