MCPcopy Create free account
hub / github.com/OpenImagingLab/4DSloMo / densify_and_split

Method densify_and_split

scene/gaussian_model.py:481–526  ·  view source on GitHub ↗
(self, grads, grad_threshold, scene_extent, grads_t, grad_t_threshold, N=2)

Source from the content-addressed store, hash-verified

479 self.max_radii2D = torch.zeros((self.get_xyz.shape[0]), device="cuda")
480
481 def densify_and_split(self, grads, grad_threshold, scene_extent, grads_t, grad_t_threshold, N=2):
482 n_init_points = self.get_xyz.shape[0]
483 # Extract points that satisfy the gradient condition
484 padded_grad = torch.zeros((n_init_points), device="cuda")
485 padded_grad[:grads.shape[0]] = grads.squeeze()
486 selected_pts_mask = torch.where(padded_grad >= grad_threshold, True, False)
487 selected_pts_mask = torch.logical_and(selected_pts_mask,
488 torch.max(self.get_scaling, dim=1).values > self.percent_dense*scene_extent)
489 # print(f"num_to_densify_pos: {torch.where(padded_grad >= grad_threshold, True, False).sum()}, num_to_split_pos: {selected_pts_mask.sum()}")
490
491 new_scaling = self.scaling_inverse_activation(self.get_scaling[selected_pts_mask].repeat(N,1) / (0.8*N))
492 new_rotation = self._rotation[selected_pts_mask].repeat(N,1)
493 new_features_dc = self._features_dc[selected_pts_mask].repeat(N,1,1)
494 new_features_rest = self._features_rest[selected_pts_mask].repeat(N,1,1)
495 new_opacity = self._opacity[selected_pts_mask].repeat(N,1)
496
497 if not self.rot_4d:
498 stds = self.get_scaling[selected_pts_mask].repeat(N,1)
499 means = torch.zeros((stds.size(0), 3),device="cuda")
500 samples = torch.normal(mean=means, std=stds)
501 rots = build_rotation(self._rotation[selected_pts_mask]).repeat(N,1,1)
502 new_xyz = torch.bmm(rots, samples.unsqueeze(-1)).squeeze(-1) + self.get_xyz[selected_pts_mask].repeat(N, 1)
503 new_t = None
504 new_scaling_t = None
505 new_rotation_r = None
506 if self.gaussian_dim == 4:
507 stds_t = self.get_scaling_t[selected_pts_mask].repeat(N,1)
508 means_t = torch.zeros((stds_t.size(0), 1),device="cuda")
509 samples_t = torch.normal(mean=means_t, std=stds_t)
510 new_t = samples_t + self.get_t[selected_pts_mask].repeat(N, 1)
511 new_scaling_t = self.scaling_inverse_activation(self.get_scaling_t[selected_pts_mask].repeat(N,1) / (0.8*N))
512 else:
513 stds = self.get_scaling_xyzt[selected_pts_mask].repeat(N,1)
514 means = torch.zeros((stds.size(0), 4),device="cuda")
515 samples = torch.normal(mean=means, std=stds)
516 rots = build_rotation_4d(self._rotation[selected_pts_mask], self._rotation_r[selected_pts_mask]).repeat(N,1,1)
517 new_xyzt = torch.bmm(rots, samples.unsqueeze(-1)).squeeze(-1) + self.get_xyzt[selected_pts_mask].repeat(N, 1)
518 new_xyz = new_xyzt[...,0:3]
519 new_t = new_xyzt[...,3:4]
520 new_scaling_t = self.scaling_inverse_activation(self.get_scaling_t[selected_pts_mask].repeat(N,1) / (0.8*N))
521 new_rotation_r = self._rotation_r[selected_pts_mask].repeat(N,1)
522
523 self.densification_postfix(new_xyz, new_features_dc, new_features_rest, new_opacity, new_scaling, new_rotation, new_t, new_scaling_t, new_rotation_r)
524
525 prune_filter = torch.cat((selected_pts_mask, torch.zeros(N * selected_pts_mask.sum(), device="cuda", dtype=bool)))
526 self.prune_points(prune_filter)
527
528 def densify_and_clone(self, grads, grad_threshold, scene_extent, grads_t, grad_t_threshold):
529 # Extract points that satisfy the gradient condition

Callers 1

densify_and_pruneMethod · 0.95

Calls 4

densification_postfixMethod · 0.95
prune_pointsMethod · 0.95
build_rotationFunction · 0.90
build_rotation_4dFunction · 0.90

Tested by

no test coverage detected