graphdeco-inria / gaussian-splatting

Original reference implementation of "3D Gaussian Splatting for Real-Time Radiance Field Rendering"
https://repo-sam.inria.fr/fungraph/3d-gaussian-splatting/
Other
13.52k stars 1.73k forks source link

+ 0? #802

Open ladzin opened 4 months ago

ladzin commented 4 months ago

Why is the "+ 0" here?

https://github.com/graphdeco-inria/gaussian-splatting/blob/472689c0dc70417448fb451bf529ae532d32c095/gaussian_renderer/__init__.py#L26

jaco001 commented 4 months ago

Code explain from copilot:

In the code you provided, the variable screenspace_points is initialized as a tensor filled with zeros, having the same dimensions as pc.get_xyz. The expression torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda") creates a tensor filled with zeros, matching the dimensions and data type of pc.get_xyz. The + 0 at the end does not affect the value of the tensor, as adding zero does not change the result. We can simplify it to:

Python

screenspace_points = torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda")
Kod wygenerowany przez sztuczną inteligencję. Przejrzyj i używaj uważnie. [Więcej informacji w Często zadawanych pytaniach](https://www.bing.com/new#faq).
The value of screenspace_points will now be a tensor of zeros with the same dimensions as pc.get_xyz, with gradients tracked (parameter requires_grad=True) and stored on the CUDA device (parameter device="cuda"). Sometimes, programmers add + 0 at the end to explicitly show that the variable is initialized as zero, but in this case, it has no impact on the result. 😊
zerolover commented 1 month ago

@ladzin after +0, screenspace_points.is_leaf = False, and we should add screenspace_points.retain_grad()

nnop commented 1 month ago

So why bother with +0?