mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-28 12:00:02 +08:00
Add temporal distortion and D-NeRF model (#825)
* Add D-NeRF temporal distortion and D-NeRF model This allows for temporal distortion to be enabled on a variety of models through config parameters, without an explicit model. Temporal distortion and MIP-NeRF are not currently jointly runnable but can be changed in the future. * Simplifying changes * Simplifying changes Co-authored-by: Matthew Tancik <tancik@berkeley.edu>
This commit is contained in:
1 parent
8678f4c2e6
commit
9ff167d705
9 files changed
+206
-7
No files matched your search
@@ -32,6 +32,7 @@ from nerfstudio.configs.base_config import InstantiateConfig
|
||||
from nerfstudio.configs.config_utils import to_immutable_dict
|
||||
from nerfstudio.data.scene_box import SceneBox
|
||||
from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes
|
||||
from nerfstudio.field_components.temporal_distortions import TemporalDistortionKind
|
||||
from nerfstudio.model_components.scene_colliders import NearFarCollider
|
||||
|
||||
|
||||
@@ -77,6 +78,7 @@ class Model(nn.Module):
|
||||
self.num_train_data = num_train_data
|
||||
self.kwargs = kwargs
|
||||
self.collider = None
|
||||
|
||||
self.populate_modules() # populate the modules
|
||||
self.callbacks = None
|
||||
# to keep track of which device the nn.Module is on
|
||||
@@ -218,3 +220,8 @@ class VanillaModelConfig(ModelConfig):
|
||||
"""Number of samples in coarse field evaluation"""
|
||||
num_importance_samples: int = 128
|
||||
"""Number of samples in fine field evaluation"""
|
||||
|
||||
enable_temporal_distortion: bool = False
|
||||
"""Specifies whether or not to include ray warping based on time."""
|
||||
temporal_distortion_params: Dict[str, Any] = to_immutable_dict({"kind": TemporalDistortionKind.DNERF})
|
||||
"""Parameters to instantiate temporal distortion with"""
|
||||
@@ -55,6 +55,7 @@ class NeRFModel(Model):
|
||||
) -> None:
|
||||
self.field_coarse = None
|
||||
self.field_fine = None
|
||||
self.temporal_distortion = None
|
||||
|
||||
super().__init__(
|
||||
config=config,
|
||||
@@ -73,8 +74,15 @@ class NeRFModel(Model):
|
||||
in_dim=3, num_frequencies=4, min_freq_exp=0.0, max_freq_exp=4.0, include_input=True
|
||||
)
|
||||
|
||||
self.field_coarse = NeRFField(position_encoding=position_encoding, direction_encoding=direction_encoding)
|
||||
self.field_fine = NeRFField(position_encoding=position_encoding, direction_encoding=direction_encoding)
|
||||
self.field_coarse = NeRFField(
|
||||
position_encoding=position_encoding,
|
||||
direction_encoding=direction_encoding,
|
||||
)
|
||||
|
||||
self.field_fine = NeRFField(
|
||||
position_encoding=position_encoding,
|
||||
direction_encoding=direction_encoding,
|
||||
)
|
||||
|
||||
# samplers
|
||||
self.sampler_uniform = UniformSampler(num_samples=self.config.num_coarse_samples)
|
||||
@@ -93,11 +101,18 @@ class NeRFModel(Model):
|
||||
self.ssim = structural_similarity_index_measure
|
||||
self.lpips = LearnedPerceptualImagePatchSimilarity()
|
||||
|
||||
if getattr(self.config, "enable_temporal_distortion", False):
|
||||
params = self.config.temporal_distortion_params
|
||||
kind = params.pop("kind")
|
||||
self.temporal_distortion = kind.to_temporal_distortion(params)
|
||||
|
||||
def get_param_groups(self) -> Dict[str, List[Parameter]]:
|
||||
param_groups = {}
|
||||
if self.field_coarse is None or self.field_fine is None:
|
||||
raise ValueError("populate_fields() must be called before get_param_groups")
|
||||
param_groups["fields"] = list(self.field_coarse.parameters()) + list(self.field_fine.parameters())
|
||||
if self.temporal_distortion is not None:
|
||||
param_groups["temporal_distortion"] = list(self.temporal_distortion.parameters())
|
||||
return param_groups
|
||||
|
||||
def get_outputs(self, ray_bundle: RayBundle):
|
||||
@@ -107,6 +122,9 @@ class NeRFModel(Model):
|
||||
|
||||
# uniform sampling
|
||||
ray_samples_uniform = self.sampler_uniform(ray_bundle)
|
||||
if self.temporal_distortion is not None:
|
||||
offsets = self.temporal_distortion(ray_samples_uniform.frustums.get_positions(), ray_samples_uniform.times)
|
||||
ray_samples_uniform.frustums.set_offsets(offsets)
|
||||
|
||||
# coarse field:
|
||||
field_outputs_coarse = self.field_coarse.forward(ray_samples_uniform)
|
||||
@@ -120,6 +138,9 @@ class NeRFModel(Model):
|
||||
|
||||
# pdf sampling
|
||||
ray_samples_pdf = self.sampler_pdf(ray_bundle, ray_samples_uniform, weights_coarse)
|
||||
if self.temporal_distortion is not None:
|
||||
offsets = self.temporal_distortion(ray_samples_pdf.frustums.get_positions(), ray_samples_pdf.times)
|
||||
ray_samples_pdf.frustums.set_offsets(offsets)
|
||||
|
||||
# fine field:
|
||||
field_outputs_fine = self.field_fine.forward(ray_samples_pdf)
|
||||
|
||||
Reference in new issue
Block a user