Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions hsplat/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ def load_2dgs_ckpt(pt_path, ch, viewmat, K, width, height, num_points=None, dev=
far_plane=200,
)

# fully_fused_projection_2dgs returns radii with shape [C, N, 2].
# gsplat.spherical_harmonics expects masks to match the batch dimensions
# of dirs, i.e. [C, N]. Collapse the last dimension of radii into a
# single boolean visibility mask.
valid_mask = (radii[..., 0] > 0) & (radii[..., 1] > 0)

camtoworlds = torch.inverse(viewmat[None])
dirs = samples["means"][None, :, :] - camtoworlds[:, None, :3, 3] # Gaussian ray directions

Expand All @@ -194,7 +200,7 @@ def load_2dgs_ckpt(pt_path, ch, viewmat, K, width, height, num_points=None, dev=
sh_opacity_degree = int(math.sqrt(sh_opacities.shape[-2]) - 1)

opacities = spherical_harmonics(
sh_opacity_degree, dirs, sh_opacities, masks=radii > 0
sh_opacity_degree, dirs, sh_opacities, masks=valid_mask
)
opacities = opacities[..., 0] # [C, N]

Expand All @@ -214,7 +220,7 @@ def load_2dgs_ckpt(pt_path, ch, viewmat, K, width, height, num_points=None, dev=
sh = sh[..., None].expand(-1, -1, 3) # [N, K, 3]

colors = spherical_harmonics(
0, dirs, sh.unsqueeze(0), masks=radii > 0
0, dirs, sh.unsqueeze(0), masks=valid_mask
)[..., 0].squeeze() # [N]
colors = torch.clamp_min(colors + 0.5, 0.0)

Expand Down Expand Up @@ -336,7 +342,9 @@ def load_gaussians(
sampled_idx = gaussian_primitives.sample_points(num_points)

# --- Culling ---
gaussian_primitives.cull_elements("gsplat_culling", radii.squeeze()[sampled_idx])
# radii has shape [C, N, 2]; derive a per-Gaussian visibility mask [N]
visibility_mask = ((radii[..., 0] > 0) & (radii[..., 1] > 0)).squeeze(0)
gaussian_primitives.cull_elements("gsplat_culling", visibility_mask[sampled_idx])
logger.info(f"Number of Gaussians after culling: {len(gaussian_primitives)}")

# Prune Gaussians with Small Scales
Expand Down
4 changes: 2 additions & 2 deletions hsplat/viz_utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import imageio.v2 as imageio
import numpy as np
import torch
from pycolmap import SceneManager
from pycolmap import Reconstruction

from .normalize import (
align_principle_axes,
Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(
colmap_dir
), f"COLMAP directory {colmap_dir} does not exist."

manager = SceneManager(colmap_dir)
manager = Reconstruction(colmap_dir)
manager.load_cameras()
manager.load_images()
manager.load_points3D()
Expand Down