MCPcopy Create free account
hub / github.com/JasonLSC/GSCodec_Studio / STG_Strategy

Class STG_Strategy

gsplat/strategy/STG_Strategy.py:13–399  ·  view source on GitHub ↗

A Densification and Pruning strategy that follows the spacetime gaussian paper:

Source from the content-addressed store, hash-verified

11
12@dataclass
13class STG_Strategy(Strategy):
14 '''A Densification and Pruning strategy that follows the spacetime gaussian paper:
15
16 '''
17 # TODO check if the following params are still needed
18 prune_opa: float = 0.005
19 grow_grad2d: float = 0.0002
20 grow_scale3d: float = 0.01
21 grow_scale2d: float = 0.05
22 prune_scale3d: float = 0.1
23 prune_scale2d: float = 0.15 # default not used
24 refine_scale2d_stop_iter: int = 0 # default not used
25 refine_start_iter: int = 500
26 refine_stop_iter: int = 9_000 # 15_000
27 reset_every: int = 3000
28 refine_every: int = 100
29 pause_refine_after_reset: int = 0
30 absgrad: bool = False
31 revised_opacity: bool = False
32 verbose: bool = False
33 # key_for_gradient: Literal["means2d", "gradient_2dgs"] = "means2d"
34
35 def initialize_state(self, scene_scale: float = 1.0) -> Dict[str, Any]:
36 """Initialize and return the running state for this strategy.
37
38 The returned state should be passed to the `step_pre_backward()` and
39 `step_post_backward()` functions.
40 """
41 # Postpone the initialization of the state to the first step so that we can
42 # put them on the correct device.
43 # - grad2d: running accum of the norm of the image plane gradients for each GS.
44 # - count: running accum of how many time each GS is visible.
45 # - radii: the radii of the GSs (normalized by the image resolution).
46 state = {"grad2d": None, "count": None, "scene_scale": scene_scale} # scene_scale = 距离场景中心最远的相机位置 - 场景中心位置
47 if self.refine_scale2d_stop_iter > 0:
48 state["radii"] = None
49 return state
50
51 def check_sanity(
52 self,
53 params: Union[Dict[str, torch.nn.Parameter], torch.nn.ParameterDict],
54 optimizers: Dict[str, torch.optim.Optimizer],
55 ):
56 """Sanity check for the parameters and optimizers.
57
58 Check if:
59 * `params` and `optimizers` have the same keys.
60 * Each optimizer has exactly one param_group, corresponding to each parameter.
61 * The following keys are present: {"means", "scales", "quats", "opacities"}.
62
63 Raises:
64 AssertionError: If any of the above conditions is not met.
65
66 .. note::
67 It is not required but highly recommended for the user to call this function
68 after initializing the strategy to ensure the convention of the parameters
69 and optimizers is as expected.
70 """

Callers 2

__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected