Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default depth output when no gaussians visible #2874

Merged
merged 5 commits into from
Feb 7, 2024

Conversation

chungmin99
Copy link
Contributor

@chungmin99 chungmin99 commented Feb 6, 2024

There should be a default "depth" value returned alongside "rgb", or the renderer may crash if there is no gaussians in the front.

More specifically, L173 and L189 will currently crash in nerfstudio if "depth" is undefined:

if self.viewer.control_panel.layer_depth:
if isinstance(self.viewer.get_model(), SplatfactoModel):
# Gaussians render much faster than we can send depth images, so we do some downsampling.
assert len(outputs["depth"].shape) == 3
assert outputs["depth"].shape[-1] == 1
desired_depth_pixels = {"low_move": 128, "low_static": 128, "high": 512}[self.state] ** 2
current_depth_pixels = outputs["depth"].shape[0] * outputs["depth"].shape[1]
scale = min(desired_depth_pixels / current_depth_pixels, 1.0)
outputs["gl_z_buf_depth"] = F.interpolate(
outputs["depth"].squeeze(dim=-1)[None, None, ...],
size=(int(outputs["depth"].shape[0] * scale), int(outputs["depth"].shape[1] * scale)),
mode="bilinear",
)[0, 0, :, :, None]
else:
# Convert to z_depth if depth compositing is enabled.
R = camera.camera_to_worlds[0, 0:3, 0:3].T
camera_ray_bundle = camera.generate_rays(camera_indices=0, obb_box=obb)
pts = camera_ray_bundle.directions * outputs["depth"]
pts = (R @ (pts.view(-1, 3).T)).T.view(*camera_ray_bundle.directions.shape)
outputs["gl_z_buf_depth"] = -pts[..., 2:3] # negative z axis is the coordinate convention

@brentyi brentyi enabled auto-merge (squash) February 7, 2024 00:16
@brentyi brentyi merged commit dc53517 into main Feb 7, 2024
2 checks passed
@brentyi brentyi deleted the cmk/add-depth-when-no-gauss branch February 7, 2024 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants