MCPcopy Index your code
hub / github.com/microsoft/TRELLIS / simplify_gs

Function simplify_gs

trellis/utils/postprocessing_utils.py:467–587  ·  view source on GitHub ↗

Simplify 3D Gaussians NOTE: this function is not used in the current implementation for the unsatisfactory performance. Args: gs (Gaussian): 3D Gaussian. simplify (float): Ratio of Gaussians to remove in simplification.

(
    gs: Gaussian,
    simplify: float = 0.95,
    verbose: bool = True,
)

Source from the content-addressed store, hash-verified

465
466
467def simplify_gs(
468 gs: Gaussian,
469 simplify: float = 0.95,
470 verbose: bool = True,
471):
472 """
473 Simplify 3D Gaussians
474 NOTE: this function is not used in the current implementation for the unsatisfactory performance.
475
476 Args:
477 gs (Gaussian): 3D Gaussian.
478 simplify (float): Ratio of Gaussians to remove in simplification.
479 """
480 if simplify <= 0:
481 return gs
482
483 # simplify
484 observations, extrinsics, intrinsics = render_multiview(gs, resolution=1024, nviews=100)
485 observations = [torch.tensor(obs / 255.0).float().cuda().permute(2, 0, 1) for obs in observations]
486
487 # Following https://arxiv.org/pdf/2411.06019
488 renderer = GaussianRenderer({
489 "resolution": 1024,
490 "near": 0.8,
491 "far": 1.6,
492 "ssaa": 1,
493 "bg_color": (0,0,0),
494 })
495 new_gs = Gaussian(**gs.init_params)
496 new_gs._features_dc = gs._features_dc.clone()
497 new_gs._features_rest = gs._features_rest.clone() if gs._features_rest is not None else None
498 new_gs._opacity = torch.nn.Parameter(gs._opacity.clone())
499 new_gs._rotation = torch.nn.Parameter(gs._rotation.clone())
500 new_gs._scaling = torch.nn.Parameter(gs._scaling.clone())
501 new_gs._xyz = torch.nn.Parameter(gs._xyz.clone())
502
503 start_lr = [1e-4, 1e-3, 5e-3, 0.025]
504 end_lr = [1e-6, 1e-5, 5e-5, 0.00025]
505 optimizer = torch.optim.Adam([
506 {"params": new_gs._xyz, "lr": start_lr[0]},
507 {"params": new_gs._rotation, "lr": start_lr[1]},
508 {"params": new_gs._scaling, "lr": start_lr[2]},
509 {"params": new_gs._opacity, "lr": start_lr[3]},
510 ], lr=start_lr[0])
511
512 def exp_anealing(optimizer, step, total_steps, start_lr, end_lr):
513 return start_lr * (end_lr / start_lr) ** (step / total_steps)
514
515 def cosine_anealing(optimizer, step, total_steps, start_lr, end_lr):
516 return end_lr + 0.5 * (start_lr - end_lr) * (1 + np.cos(np.pi * step / total_steps))
517
518 _zeta = new_gs.get_opacity.clone().detach().squeeze()
519 _lambda = torch.zeros_like(_zeta)
520 _delta = 1e-7
521 _interval = 10
522 num_target = int((1 - simplify) * _zeta.shape[0])
523
524 with tqdm(total=2500, disable=not verbose, desc='Simplifying Gaussian') as pbar:

Callers

nothing calls this directly

Calls 8

renderMethod · 0.95
render_multiviewFunction · 0.85
GaussianRendererClass · 0.85
GaussianClass · 0.85
cosine_anealingFunction · 0.85
floatMethod · 0.80
detachMethod · 0.80
cudaMethod · 0.45

Tested by

no test coverage detected