mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 05:48:57 +08:00
adding density initalization at origin
This commit is contained in:
1 parent
96dd90fca2
commit
8e120e5b58
1 file changed
+35
-2
@@ -29,6 +29,11 @@ from torchmetrics.functional import structural_similarity_index_measure
|
|||||||
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
|
from nerfstudio.engine.callbacks import (
|
||||||
|
TrainingCallback,
|
||||||
|
TrainingCallbackAttributes,
|
||||||
|
TrainingCallbackLocation,
|
||||||
|
)
|
||||||
|
|
||||||
# from nerfstudio.field_components.encodings import NeRFEncoding,
|
# from nerfstudio.field_components.encodings import NeRFEncoding,
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
@@ -63,7 +68,7 @@ class DreamFusionModelConfig(ModelConfig):
|
|||||||
"""Orientation loss multipier on computed normals."""
|
"""Orientation loss multipier on computed normals."""
|
||||||
pred_normal_loss_mult: float = 0.001
|
pred_normal_loss_mult: float = 0.001
|
||||||
"""Predicted normal loss multiplier."""
|
"""Predicted normal loss multiplier."""
|
||||||
random_light_source: bool = True
|
random_light_source: bool = False
|
||||||
"""Randomizes light source per output."""
|
"""Randomizes light source per output."""
|
||||||
|
|
||||||
|
|
||||||
@@ -82,8 +87,29 @@ class DreamFusionModel(Model):
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.num_samples = config.num_samples
|
self.num_samples = config.num_samples
|
||||||
|
self.initialize_density = True
|
||||||
super().__init__(config=config, **kwargs)
|
super().__init__(config=config, **kwargs)
|
||||||
|
|
||||||
|
def get_training_callbacks(
|
||||||
|
self, training_callback_attributes: TrainingCallbackAttributes
|
||||||
|
) -> List[TrainingCallback]:
|
||||||
|
|
||||||
|
# the callback that we want to run every X iterations after the training iteration
|
||||||
|
def stop_initialize_density(
|
||||||
|
self, training_callback_attributes: TrainingCallbackAttributes, step: int # pylint: disable=unused-argument
|
||||||
|
):
|
||||||
|
self.initialize_density = False
|
||||||
|
|
||||||
|
callbacks = [
|
||||||
|
TrainingCallback(
|
||||||
|
where_to_run=[TrainingCallbackLocation.AFTER_TRAIN_ITERATION],
|
||||||
|
iters=(1000,),
|
||||||
|
func=stop_initialize_density,
|
||||||
|
args=[self, training_callback_attributes],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
return callbacks
|
||||||
|
|
||||||
def populate_modules(self):
|
def populate_modules(self):
|
||||||
"""Set the fields and modules"""
|
"""Set the fields and modules"""
|
||||||
super().populate_modules()
|
super().populate_modules()
|
||||||
@@ -123,7 +149,14 @@ class DreamFusionModel(Model):
|
|||||||
# uniform sampling
|
# uniform sampling
|
||||||
ray_samples_uniform = self.sampler_uniform(ray_bundle)
|
ray_samples_uniform = self.sampler_uniform(ray_bundle)
|
||||||
field_outputs = self.field(ray_samples_uniform, compute_normals=True)
|
field_outputs = self.field(ray_samples_uniform, compute_normals=True)
|
||||||
weights = ray_samples_uniform.get_weights(field_outputs[FieldHeadNames.DENSITY])
|
|
||||||
|
density = field_outputs[FieldHeadNames.DENSITY]
|
||||||
|
if self.initialize_density:
|
||||||
|
pos = ray_samples_uniform.frustums.get_positions()
|
||||||
|
density_blob = 10 * torch.exp(-torch.norm(pos, dim=-1) / (2 * 0.04))[..., None]
|
||||||
|
density += density_blob
|
||||||
|
|
||||||
|
weights = ray_samples_uniform.get_weights(density)
|
||||||
|
|
||||||
accumulation = self.renderer_accumulation(weights)
|
accumulation = self.renderer_accumulation(weights)
|
||||||
depth = self.renderer_depth(weights, ray_samples_uniform)
|
depth = self.renderer_depth(weights, ray_samples_uniform)
|
||||||
|
|||||||
Reference in new issue
Block a user