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

Bug in 'cotcurv' mesh_laplacian_smoothing #551

Closed
shubham-goel opened this issue Feb 4, 2021 · 2 comments
Closed

Bug in 'cotcurv' mesh_laplacian_smoothing #551

shubham-goel opened this issue Feb 4, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@shubham-goel
Copy link
Contributor

🐛 Bugs / Unexpected behaviors

The cotcurv method of the mesh_laplacian_smoothing function is supposed to compute loss as:
\sum_j w_ij(u_j - u_i) / (4 A[i])
where w_ij = (cot a_ij + cot b_ij) following reference [1] in the docs.

However, the implementation does not follow this, and computes loss as:
(\sum_j (w_ij u_j) - u_i) / (4 A[i])

loss = (L.mm(verts_packed) - verts_packed) * norm_w

These two aren't equivalent as \sum_j w_ij doesn't sum-up to 1.

Instructions To Reproduce the Issue:

The effect of this bug is evident when you compute the cotcurv laplacian loss for ico-spheres of different levels. Since the 'cotcurv' laplacian is supposed to capture mean curvature, we expect the laplacian loss to be the same at different level ico-spheres. However, that's not the case:

for i in range(5):
    print(mesh_laplacian_smoothing(ico_sphere(i), 'cotcurv'))

# Output:
# tensor(0.1652)
# tensor(1.3907)
# tensor(6.1977)
# tensor(25.4255)
# tensor(102.4149)

The implementation can be fixed as:

L_sum = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
loss = (L.mm(verts_packed) - L_sum*verts_packed) * norm_w

Once fixed, the cotcurv laplacian loss remains same across different ico_sphere levels:

for i in range(5):
    print(mesh_laplacian_smoothing(ico_sphere(i), 'cotcurv'))

# Output:
# tensor(0.3333)
# tensor(0.3354)
# tensor(0.3341)
# tensor(0.3335)
# tensor(0.3334)
@gkioxari
Copy link
Contributor

gkioxari commented Feb 4, 2021

I implemented those and there is a high chance you are right. I don't quite remember the details now but I can check them soon. If you want you can submit a PR with the fix and I will review it!

@gkioxari gkioxari added the bug Something isn't working label Feb 4, 2021
shubham-goel added a commit to shubham-goel/pytorch3d that referenced this issue Feb 4, 2021
@shubham-goel
Copy link
Contributor Author

Thank you! I've created a PR: #553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants