Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward formula #89

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 12 additions & 6 deletions taichi_3d_gaussian_splatting/GaussianPointCloudRasterisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,9 @@ def gaussian_point_rasterisation_backward(
# let w_i = \sum_{j=i+1}^{n} c_j a_j T(j)
# we have w_n = 0, w_{i-1} = w_i + c_i a_i T(i)
# \frac{dC}{da_i} = c_i T(i) - \frac{1}{1 - a_i} w_i
w_i = ti.math.vec3(0.0, 0.0, 0.0)
accum_res = ti.math.vec3(0.0, 0.0, 0.0)
prev_color = ti.math.vec3(0.0, 0.0, 0.0)
prev_alpha:ti.f32 = 0.0

pixel_rgb_grad = ti.math.vec3(
rasterized_image_grad[pixel_v, pixel_u, 0], rasterized_image_grad[pixel_v, pixel_u, 1], rasterized_image_grad[pixel_v, pixel_u, 2])
Expand Down Expand Up @@ -769,12 +771,16 @@ def gaussian_point_rasterisation_backward(
point_grad_color = d_pixel_rgb_d_color * pixel_rgb_grad

# \frac{dC}{da_i} = c_i T(i) - \frac{1}{1 - a_i} w_i
alpha_grad_from_rgb = (color * T_i - w_i / (1. - alpha)) \
* pixel_rgb_grad
# alpha_grad_from_rgb = (color * T_i - w_i / (1. - alpha)) \
# * pixel_rgb_grad
accum_res = prev_alpha * prev_color + (1. - prev_alpha) * accum_res
prev_color = color
alpha_grad = ((color - accum_res) * pixel_rgb_grad).sum() * T_i
prev_alpha = alpha
# w_{i-1} = w_i + c_i a_i T(i)
w_i += color * alpha * T_i
alpha_grad: ti.f32 = alpha_grad_from_rgb[0] + \
alpha_grad_from_rgb[1] + alpha_grad_from_rgb[2]
# w_i += color * alpha * T_i
# alpha_grad: ti.f32 = alpha_grad_from_rgb[0] + \
# alpha_grad_from_rgb[1] + alpha_grad_from_rgb[2]
point_alpha_after_activation_grad = alpha_grad * gaussian_alpha
gaussian_point_3d_alpha_grad = point_alpha_after_activation_grad * \
(1. - point_alpha_after_activation_value) * \
Expand Down
1 change: 1 addition & 0 deletions taichi_3d_gaussian_splatting/GaussianPointCloudScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def from_parquet(path: str, config=PointCloudSceneConfig()):
scene = GaussianPointCloudScene(
point_cloud, config)


point_cloud_rgb = scene_df[["r", "g", "b"]
].to_numpy() if df_has_color else None
scene.initialize(point_cloud_rgb=point_cloud_rgb)
Expand Down