Skip to content

Commit e13e63a

Browse files
shubham-goelfacebook-github-bot
authored andcommitted
bugfix in cotcurv laplacian loss. closes #551 (#553)
Summary: Pull Request resolved: #553 Reviewed By: theschnitz Differential Revision: D26257591 Pulled By: gkioxari fbshipit-source-id: 899a3f733a77361e8572b0900a34b55764ff08f2
1 parent 17468e2 commit e13e63a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pytorch3d/loss/mesh_laplacian_smoothing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def mesh_laplacian_smoothing(meshes, method: str = "uniform"):
108108
idx = norm_w > 0
109109
norm_w[idx] = 1.0 / norm_w[idx]
110110
else:
111+
L_sum = torch.sparse.sum(L, dim=1).to_dense().view(-1, 1)
111112
norm_w = 0.25 * inv_areas
112113
else:
113114
raise ValueError("Method should be one of {uniform, cot, cotcurv}")
@@ -117,7 +118,7 @@ def mesh_laplacian_smoothing(meshes, method: str = "uniform"):
117118
elif method == "cot":
118119
loss = L.mm(verts_packed) * norm_w - verts_packed
119120
elif method == "cotcurv":
120-
loss = (L.mm(verts_packed) - verts_packed) * norm_w
121+
loss = (L.mm(verts_packed) - L_sum * verts_packed) * norm_w
121122
loss = loss.norm(dim=1)
122123

123124
loss = loss * weights

tests/test_mesh_laplacian_smoothing.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ def laplacian_smoothing_naive_cot(meshes, method: str = "cot"):
8989
inv_areas[idx] = 1.0 / inv_areas[idx]
9090

9191
norm_w = L.sum(dim=1, keepdims=True)
92+
L_sum = norm_w.clone()
9293
idx = norm_w > 0
9394
norm_w[idx] = 1.0 / norm_w[idx]
9495

9596
if method == "cotcurv":
96-
loss = (L.mm(verts_packed) - verts_packed) * inv_areas * 0.25
97+
loss = (L.mm(verts_packed) - L_sum * verts_packed) * inv_areas * 0.25
9798
loss = loss.norm(dim=1)
9899
else:
99100
loss = L.mm(verts_packed) * norm_w - verts_packed
@@ -147,7 +148,7 @@ def test_laplacian_smoothing_uniform(self):
147148

148149
def test_laplacian_smoothing_cot(self):
149150
"""
150-
Test Laplacian Smoothing with uniform weights.
151+
Test Laplacian Smoothing with cot weights.
151152
"""
152153
meshes = TestLaplacianSmoothing.init_meshes(10, 100, 300)
153154

@@ -161,7 +162,7 @@ def test_laplacian_smoothing_cot(self):
161162

162163
def test_laplacian_smoothing_cotcurv(self):
163164
"""
164-
Test Laplacian Smoothing with uniform weights.
165+
Test Laplacian Smoothing with cotcurv weights.
165166
"""
166167
meshes = TestLaplacianSmoothing.init_meshes(10, 100, 300)
167168

0 commit comments

Comments
 (0)