This commit is contained in:
Justin Kerr committed 2024-05-27 11:03:39 -07:00
1 parent 62f3e6dc86
commit 1f63072852
3 files changed
+18 -9

No files matched your search

+3 -2
View File
@@ -27,7 +27,7 @@ from nerfstudio.cameras.camera_optimizers import CameraOptimizerConfig
from nerfstudio.configs.base_config import ViewerConfig from nerfstudio.configs.base_config import ViewerConfig
from nerfstudio.configs.external_methods import ExternalMethodDummyTrainerConfig, get_external_methods from nerfstudio.configs.external_methods import ExternalMethodDummyTrainerConfig, get_external_methods
from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManager, VanillaDataManagerConfig from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManager, VanillaDataManagerConfig
from nerfstudio.data.datamanagers.full_images_datamanager import FullImageDatamanagerConfig from nerfstudio.data.datamanagers.full_images_datamanager import FullImageDatamanagerConfig,FullImageDatamanager
from nerfstudio.data.datamanagers.parallel_datamanager import ParallelDataManagerConfig from nerfstudio.data.datamanagers.parallel_datamanager import ParallelDataManagerConfig
from nerfstudio.data.datamanagers.random_cameras_datamanager import RandomCamerasDataManagerConfig from nerfstudio.data.datamanagers.random_cameras_datamanager import RandomCamerasDataManagerConfig
from nerfstudio.data.dataparsers.blender_dataparser import BlenderDataParserConfig from nerfstudio.data.dataparsers.blender_dataparser import BlenderDataParserConfig
@@ -601,7 +601,8 @@ method_configs["splatfacto"] = TrainerConfig(
mixed_precision=False, mixed_precision=False,
pipeline=VanillaPipelineConfig( pipeline=VanillaPipelineConfig(
datamanager=FullImageDatamanagerConfig( datamanager=FullImageDatamanagerConfig(
dataparser=NerfstudioDataParserConfig(load_3D_points=True), _target=FullImageDatamanager[DepthDataset],
dataparser=NerfstudioDataParserConfig(load_3D_points=True,depth_unit_scale_factor=1.0),
cache_images_type="uint8", cache_images_type="uint8",
), ),
model=SplatfactoModelConfig(), model=SplatfactoModelConfig(),
@@ -200,14 +200,16 @@ class FullImageDatamanager(DataManager, Generic[TDataset]):
cache["image"] = cache["image"].to(self.device) cache["image"] = cache["image"].to(self.device)
if "mask" in cache: if "mask" in cache:
cache["mask"] = cache["mask"].to(self.device) cache["mask"] = cache["mask"].to(self.device)
if "depth" in cache: if "depth_image" in cache:
cache["depth"] = cache["depth"].to(self.device) cache["depth_image"] = cache["depth_image"].to(self.device)
self.train_cameras = self.train_dataset.cameras.to(self.device) self.train_cameras = self.train_dataset.cameras.to(self.device)
elif cache_images_device == "cpu": elif cache_images_device == "cpu":
for cache in undistorted_images: for cache in undistorted_images:
cache["image"] = cache["image"].pin_memory() cache["image"] = cache["image"].pin_memory()
if "mask" in cache: if "mask" in cache:
cache["mask"] = cache["mask"].pin_memory() cache["mask"] = cache["mask"].pin_memory()
if "depth_image" in cache:
cache["depth_image"] = cache["depth_image"].to(self.device)
self.train_cameras = self.train_dataset.cameras self.train_cameras = self.train_dataset.cameras
else: else:
assert_never(cache_images_device) assert_never(cache_images_device)
+11 -5
View File
@@ -98,7 +98,7 @@ def resize_image(image: torch.Tensor, d: int):
return tf.conv2d(image.permute(2, 0, 1)[:, None, ...], weight, stride=d).squeeze(1).permute(1, 2, 0) return tf.conv2d(image.permute(2, 0, 1)[:, None, ...], weight, stride=d).squeeze(1).permute(1, 2, 0)
@torch.compile(dynamic=False) @torch.compile()
def get_viewmat(optimized_camera_to_world): def get_viewmat(optimized_camera_to_world):
""" """
function that converts c2w to gsplat world2camera matrix, using compile for some speed function that converts c2w to gsplat world2camera matrix, using compile for some speed
@@ -171,7 +171,7 @@ class SplatfactoModelConfig(ModelConfig):
"""threshold of ratio of gaussian max to min scale before applying regularization """threshold of ratio of gaussian max to min scale before applying regularization
loss from the PhysGaussian paper loss from the PhysGaussian paper
""" """
output_depth_during_training: bool = False output_depth_during_training: bool = True
"""If True, output depth during training. Otherwise, only output depth during evaluation.""" """If True, output depth during training. Otherwise, only output depth during evaluation."""
rasterize_mode: Literal["classic", "antialiased"] = "classic" rasterize_mode: Literal["classic", "antialiased"] = "classic"
""" """
@@ -723,7 +723,7 @@ class SplatfactoModel(Model):
raise ValueError("Unknown rasterize_mode: %s", self.config.rasterize_mode) raise ValueError("Unknown rasterize_mode: %s", self.config.rasterize_mode)
if self.config.output_depth_during_training or not self.training: if self.config.output_depth_during_training or not self.training:
render_mode = "RGB+D" render_mode = "RGB+ED"
else: else:
render_mode = "RGB" render_mode = "RGB"
@@ -761,7 +761,7 @@ class SplatfactoModel(Model):
alpha = alpha[0, ...] alpha = alpha[0, ...]
rgb = render[0, ..., :3] + (1 - alpha) * background rgb = render[0, ..., :3] + (1 - alpha) * background
rgb = torch.clamp(rgb, 0.0, 1.0) rgb = torch.clamp(rgb, 0.0, 1.0)
if render_mode == "RGB+D": if render_mode == "RGB+ED":
depth_im = render[0, ..., 3:4] depth_im = render[0, ..., 3:4]
depth_im = torch.where(alpha > 0, depth_im, depth_im.detach().max()) depth_im = torch.where(alpha > 0, depth_im, depth_im.detach().max())
else: else:
@@ -845,10 +845,16 @@ class SplatfactoModel(Model):
scale_reg = 0.1 * scale_reg.mean() scale_reg = 0.1 * scale_reg.mean()
else: else:
scale_reg = torch.tensor(0.0).to(self.device) scale_reg = torch.tensor(0.0).to(self.device)
if 'depth_image' in batch:
gt_depth = self.get_gt_img(batch['depth_image'])
ignores = gt_depth == 0
depth_loss = (gt_depth - outputs['depth'])[~ignores].abs().mean()
else:
depth_loss = torch.tensor(0.0).to(self.device)
loss_dict = { loss_dict = {
"main_loss": (1 - self.config.ssim_lambda) * Ll1 + self.config.ssim_lambda * simloss, "main_loss": (1 - self.config.ssim_lambda) * Ll1 + self.config.ssim_lambda * simloss,
"scale_reg": scale_reg, "scale_reg": scale_reg,
'depth_loss':depth_loss
} }
if self.training: if self.training: