mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 07:48:50 +08:00
Don't train normals for first 1k iters
This commit is contained in:
1 parent
0447b5219b
commit
bd4988c57e
2 files changed
+33
-16
No files matched your search
@@ -64,12 +64,14 @@ class DreamFusionModelConfig(ModelConfig):
|
|||||||
|
|
||||||
num_samples: int = 256
|
num_samples: int = 256
|
||||||
"""Number of samples in field evaluation"""
|
"""Number of samples in field evaluation"""
|
||||||
orientation_loss_mult: float = 0.0001
|
orientation_loss_mult: float = 0.01
|
||||||
"""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.0003
|
||||||
"""Predicted normal loss multiplier."""
|
"""Predicted normal loss multiplier."""
|
||||||
random_light_source: bool = False
|
random_light_source: bool = False
|
||||||
"""Randomizes light source per output."""
|
"""Randomizes light source per output."""
|
||||||
|
initialize_density: bool = True
|
||||||
|
"""Initialize density in center of scene."""
|
||||||
|
|
||||||
|
|
||||||
class DreamFusionModel(Model):
|
class DreamFusionModel(Model):
|
||||||
@@ -87,7 +89,8 @@ class DreamFusionModel(Model):
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.num_samples = config.num_samples
|
self.num_samples = config.num_samples
|
||||||
self.initialize_density = True
|
self.initialize_density = config.initialize_density
|
||||||
|
self.train_normals = False
|
||||||
super().__init__(config=config, **kwargs)
|
super().__init__(config=config, **kwargs)
|
||||||
|
|
||||||
def get_training_callbacks(
|
def get_training_callbacks(
|
||||||
@@ -100,13 +103,24 @@ class DreamFusionModel(Model):
|
|||||||
):
|
):
|
||||||
self.initialize_density = False
|
self.initialize_density = False
|
||||||
|
|
||||||
|
def start_training_normals(
|
||||||
|
self, training_callback_attributes: TrainingCallbackAttributes, step: int # pylint: disable=unused-argument
|
||||||
|
):
|
||||||
|
self.train_normals = True
|
||||||
|
|
||||||
callbacks = [
|
callbacks = [
|
||||||
TrainingCallback(
|
TrainingCallback(
|
||||||
where_to_run=[TrainingCallbackLocation.AFTER_TRAIN_ITERATION],
|
where_to_run=[TrainingCallbackLocation.AFTER_TRAIN_ITERATION],
|
||||||
iters=(1000,),
|
iters=(1000,),
|
||||||
func=stop_initialize_density,
|
func=stop_initialize_density,
|
||||||
args=[self, training_callback_attributes],
|
args=[self, training_callback_attributes],
|
||||||
)
|
),
|
||||||
|
TrainingCallback(
|
||||||
|
where_to_run=[TrainingCallbackLocation.AFTER_TRAIN_ITERATION],
|
||||||
|
iters=(1000,),
|
||||||
|
func=start_training_normals,
|
||||||
|
args=[self, training_callback_attributes],
|
||||||
|
),
|
||||||
]
|
]
|
||||||
return callbacks
|
return callbacks
|
||||||
|
|
||||||
@@ -161,6 +175,13 @@ class DreamFusionModel(Model):
|
|||||||
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)
|
||||||
rgb = self.renderer_rgb(rgb=field_outputs[FieldHeadNames.RGB], weights=weights)
|
rgb = self.renderer_rgb(rgb=field_outputs[FieldHeadNames.RGB], weights=weights)
|
||||||
|
|
||||||
|
outputs = {
|
||||||
|
"rgb": rgb,
|
||||||
|
"accumulation": accumulation,
|
||||||
|
"depth": depth,
|
||||||
|
}
|
||||||
|
|
||||||
normals = self.renderer_normals(normals=field_outputs[FieldHeadNames.NORMALS], weights=weights)
|
normals = self.renderer_normals(normals=field_outputs[FieldHeadNames.NORMALS], weights=weights)
|
||||||
pred_normals = self.renderer_normals(field_outputs[FieldHeadNames.PRED_NORMALS], weights=weights)
|
pred_normals = self.renderer_normals(field_outputs[FieldHeadNames.PRED_NORMALS], weights=weights)
|
||||||
|
|
||||||
@@ -177,17 +198,13 @@ class DreamFusionModel(Model):
|
|||||||
shaded = lambertian.unsqueeze(-1).repeat(1, 3)
|
shaded = lambertian.unsqueeze(-1).repeat(1, 3)
|
||||||
shaded_albedo = rgb * lambertian.unsqueeze(-1)
|
shaded_albedo = rgb * lambertian.unsqueeze(-1)
|
||||||
|
|
||||||
outputs = {
|
outputs["normals"] = normals
|
||||||
"rgb": rgb,
|
outputs["pred_normals"] = pred_normals
|
||||||
"accumulation": accumulation,
|
outputs["shaded"] = shaded
|
||||||
"depth": depth,
|
outputs["shaded_albedo"] = shaded_albedo
|
||||||
"normals": normals,
|
|
||||||
"pred_normals": pred_normals,
|
if self.train_normals:
|
||||||
"shaded": shaded,
|
|
||||||
"shaded_albedo": shaded_albedo,
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.training:
|
|
||||||
outputs["rendered_orientation_loss"] = orientation_loss(
|
outputs["rendered_orientation_loss"] = orientation_loss(
|
||||||
weights.detach(), field_outputs[FieldHeadNames.NORMALS], ray_bundle.directions
|
weights.detach(), field_outputs[FieldHeadNames.NORMALS], ray_bundle.directions
|
||||||
)
|
)
|
||||||
@@ -210,7 +227,7 @@ class DreamFusionModel(Model):
|
|||||||
|
|
||||||
loss_dict = {"rgb_loss": rgb_loss}
|
loss_dict = {"rgb_loss": rgb_loss}
|
||||||
loss_dict = misc.scale_dict(loss_dict, self.config.loss_coefficients)
|
loss_dict = misc.scale_dict(loss_dict, self.config.loss_coefficients)
|
||||||
if self.training:
|
if self.train_normals:
|
||||||
# orientation loss for computed normals
|
# orientation loss for computed normals
|
||||||
loss_dict["orientation_loss"] = self.config.orientation_loss_mult * torch.mean(
|
loss_dict["orientation_loss"] = self.config.orientation_loss_mult * torch.mean(
|
||||||
outputs["rendered_orientation_loss"]
|
outputs["rendered_orientation_loss"]
|
||||||
|
|||||||
@@ -625,7 +625,7 @@ export default function CameraPanel(props) {
|
|||||||
labelDiv.className = 'label';
|
labelDiv.className = 'label';
|
||||||
labelDiv.textContent = camera.properties.get('NAME');
|
labelDiv.textContent = camera.properties.get('NAME');
|
||||||
labelDiv.style.color = 'black';
|
labelDiv.style.color = 'black';
|
||||||
labelDiv.style.backgroundColor = "rgba(255, 255, 255, 0.61)";
|
labelDiv.style.backgroundColor = 'rgba(255, 255, 255, 0.61)';
|
||||||
labelDiv.style.backdropFilter = 'blur(5px)';
|
labelDiv.style.backdropFilter = 'blur(5px)';
|
||||||
labelDiv.style.padding = '6px';
|
labelDiv.style.padding = '6px';
|
||||||
labelDiv.style.borderRadius = '6px';
|
labelDiv.style.borderRadius = '6px';
|
||||||
|
|||||||
Reference in new issue
Block a user