visibility depth nerfacto

This commit is contained in:
Ethan Weber committed 2024-03-05 01:57:05 +00:00
1 parent 1717a2fc2f
commit 27aa29988a
3 files changed
+30 -26

No files matched your search

+28 -25
View File
@@ -71,10 +71,6 @@ class DepthNerfactoModel(NerfactoModel):
else: else:
self.depth_sigma = torch.tensor([self.config.depth_sigma]) self.depth_sigma = torch.tensor([self.config.depth_sigma])
# self.collider = NearFarCollider(near_plane=self.config.near_plane, far_plane=self.config.far_plane)
# import pdb; pdb.set_trace();
self.collider = AABBBoxCollider(scene_box=self.scene_box)
def get_outputs(self, ray_bundle: RayBundle): def get_outputs(self, ray_bundle: RayBundle):
outputs = super().get_outputs(ray_bundle) outputs = super().get_outputs(ray_bundle)
if ray_bundle.metadata is not None and "directions_norm" in ray_bundle.metadata: if ray_bundle.metadata is not None and "directions_norm" in ray_bundle.metadata:
@@ -91,27 +87,34 @@ class DepthNerfactoModel(NerfactoModel):
raise ValueError( raise ValueError(
f"Forcing pseudodepth loss, but depth loss type ({self.config.depth_loss_type}) must be one of {losses.PSEUDODEPTH_COMPATIBLE_LOSSES}" f"Forcing pseudodepth loss, but depth loss type ({self.config.depth_loss_type}) must be one of {losses.PSEUDODEPTH_COMPATIBLE_LOSSES}"
) )
if self.config.depth_loss_type in (DepthLossType.DS_NERF, DepthLossType.URF): # if self.config.depth_loss_type in (DepthLossType.DS_NERF, DepthLossType.URF):
metrics_dict["depth_loss"] = 0.0 # metrics_dict["depth_loss"] = 0.0
sigma = self._get_sigma().to(self.device) # sigma = self._get_sigma().to(self.device)
termination_depth = batch["depth_image"].to(self.device) # termination_depth = batch["depth_image"].to(self.device)
for i in range(len(outputs["weights_list"])): # for i in range(len(outputs["weights_list"])):
metrics_dict["depth_loss"] += depth_loss( # metrics_dict["depth_loss"] += depth_loss(
weights=outputs["weights_list"][i], # weights=outputs["weights_list"][i],
ray_samples=outputs["ray_samples_list"][i], # ray_samples=outputs["ray_samples_list"][i],
termination_depth=termination_depth, # termination_depth=termination_depth,
predicted_depth=outputs["expected_depth"], # predicted_depth=outputs["expected_depth"],
sigma=sigma, # sigma=sigma,
directions_norm=outputs["directions_norm"], # directions_norm=outputs["directions_norm"],
is_euclidean=self.config.is_euclidean_depth, # is_euclidean=self.config.is_euclidean_depth,
depth_loss_type=self.config.depth_loss_type, # depth_loss_type=self.config.depth_loss_type,
) / len(outputs["weights_list"]) # ) / len(outputs["weights_list"])
elif self.config.depth_loss_type in (DepthLossType.SPARSENERF_RANKING,): # elif self.config.depth_loss_type in (DepthLossType.SPARSENERF_RANKING,):
metrics_dict["depth_ranking"] = depth_ranking_loss( # metrics_dict["depth_ranking"] = depth_ranking_loss(
outputs["expected_depth"], batch["depth_image"].to(self.device) # outputs["expected_depth"], batch["depth_image"].to(self.device)
) # )
else: # else:
raise NotImplementedError(f"Unknown depth loss type {self.config.depth_loss_type}") # raise NotImplementedError(f"Unknown depth loss type {self.config.depth_loss_type}")
termination_depth = batch["depth_image"].to(self.device)
predicted_depth = outputs["expected_depth"]
# import pdb; pdb.set_trace();
if not self.config.is_euclidean_depth:
termination_depth = termination_depth * outputs["directions_norm"]
metrics_dict["depth_loss"] = torch.mean((termination_depth - predicted_depth) ** 2)
return metrics_dict return metrics_dict
+1 -1
View File
@@ -179,7 +179,7 @@ class NerfactoModel(Model):
implementation=self.config.implementation, implementation=self.config.implementation,
) )
self.camera_optimizer: CameraOptimizer = self.config.camera_optimizer.setup( self.camera_optimizer: CameraOptimizer = self.config.camera_optimizer.setup(
num_cameras=self.num_train_data, device="cpu" num_cameras=self.num_train_data, device="cpu")
# this can be set by the pipeline # this can be set by the pipeline
# if set, then we create a visibility outputs # if set, then we create a visibility outputs
self.visibility_field: Optional[VisibilityField] = None self.visibility_field: Optional[VisibilityField] = None
+1
View File
@@ -44,6 +44,7 @@ from nerfstudio.cameras.cameras import Cameras
from nerfstudio.fields.visibility_field import VisibilityField from nerfstudio.fields.visibility_field import VisibilityField
from nerfstudio.utils.misc import step_check from nerfstudio.utils.misc import step_check
from nerfstudio.data.datamanagers.random_cameras_datamanager import random_train_pose from nerfstudio.data.datamanagers.random_cameras_datamanager import random_train_pose
import math
def module_wrapper(ddp_or_model: Union[DDP, Model]) -> Model: def module_wrapper(ddp_or_model: Union[DDP, Model]) -> Model: