Calculate Gaussian Flow for 4D Content Creation
mainGaussianFlow calculates the predicted flow of Gaussians between two time steps ($t_1$ and $t_2$). To accelerate training, variables related to $t_1$ (such as conic_2D) should be detached from the gradient graph using .detach(). This ensures that the backward pass only updates variables at $t_2$, as $t_1$ variables were already updated in the previous step ($t_1 - 1$).
To implement this, you need:
- Gaussian parameters at $t_1$ (e.g.,
proj_2D,gs_per_pixel,weight_per_gs_pixel,x_mu, andconic_2D). - Gaussian parameters at $t_2$ (e.g.,
proj_2D,conic_2D, andconic_2D_inv). - A CUDA implementation for calculating Gaussian flow variables (refer to the
diff-gaussian-rasterizationrepository for the underlying CUDA kernels).
### We detach the variables related to t_1 in calculation of GaussianFlow such that the gradient backward
### only works for variables at t_2 while keeping variables at t_1 unchanged because
### variables at t_1 have been updated at t_1 - 1 with the same logic.
# Gaussian parameters at t_1
proj_2D_t_1 = render_t_1["proj_2D"]
gs_per_pixel = render_t_1["gs_per_pixel"].long()
weight_per_gs_pixel = render_t_1["weight_per_gs_pixel"]
x_mu = render_t_1["x_mu"]
cov2D_inv_t_1 = render_t_1["conic_2D"].detach()
# Gaussian parameters at t_2
proj_2D_t_2 = render_t_2["proj_2D"]
cov2D_inv_t_2 = render_t_2["conic_2D"]
cov2D_t_2 = render_t_2["conic_2D_inv"]
# ... (calculation of B_t_2 and B_inv_t_1) ...
# full formulation of GaussianFlow
cov_multi = (B_t_2_B_inv_t_1[gs_per_pixel] @ x_mu.permute(0,2,3,1).unsqueeze(-1).detach()).squeeze()
predicted_flow_by_gs = (cov_multi + proj_2D_next[gs_per_pixel] - proj_2D[gs_per_pixel].detach() - x_mu.permute(0,2,3,1).detach()) * weights.detach()