Skip to content

Commit

Permalink
Add alpha rendering to splatfacto, fix depth bug (nerfstudio-project#…
Browse files Browse the repository at this point in the history
…2824)

* Add alpha rendering to splatfacto, output as accumulation
  • Loading branch information
kerrj authored and ArpegorPSGH committed Jun 22, 2024
1 parent 15fbc41 commit aafbded
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions nerfstudio/models/splatfacto.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def get_outputs(self, camera: Cameras) -> Dict[str, Union[torch.Tensor, List]]:
# rescale the camera back to original dimensions
camera.rescale_output_resolution(camera_downscale)
assert (num_tiles_hit > 0).any() # type: ignore
rgb = rasterize_gaussians( # type: ignore
rgb, alpha = rasterize_gaussians( # type: ignore
self.xys,
depths,
self.radii,
Expand All @@ -759,7 +759,9 @@ def get_outputs(self, camera: Cameras) -> Dict[str, Union[torch.Tensor, List]]:
H,
W,
background=background,
return_alpha=True,
) # type: ignore
alpha = alpha[..., None]
rgb = torch.clamp(rgb, max=1.0) # type: ignore
depth_im = None
if not self.training:
Expand All @@ -773,10 +775,12 @@ def get_outputs(self, camera: Cameras) -> Dict[str, Union[torch.Tensor, List]]:
torch.sigmoid(opacities_crop),
H,
W,
background=torch.ones(3, device=self.device) * 10,
background=torch.zeros(3, device=self.device),
)[..., 0:1] # type: ignore
depth_im[alpha > 0] = depth_im[alpha > 0] / alpha[alpha > 0]
depth_im[alpha == 0] = 1000

return {"rgb": rgb, "depth": depth_im} # type: ignore
return {"rgb": rgb, "depth": depth_im, "accumulation": alpha} # type: ignore

def get_gt_img(self, image: torch.Tensor):
"""Compute groundtruth image with iteration dependent downscale factor for evaluation purpose
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies = [
"xatlas",
"trimesh>=3.20.2",
"timm==0.6.7",
"gsplat==0.1.2.1",
"gsplat==0.1.3",
"pytorch-msssim",
"pathos",
"packaging"
Expand Down

0 comments on commit aafbded

Please sign in to comment.