Closed SMY19999 closed 5 months ago
When I try to do the backward() as the following:
lap_single = lap_single.norm()
lap_single.backward()
It reports:
Traceback (most recent call last):
File "xxxx//IPython/core/interactiveshell.py", line 3508, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-606074cc5014>", line 1, in <module>
runfile('xxxx/laplacian.py', wdir='xxxx')
File "/snap/pycharm-community/383/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/snap/pycharm-community/383/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "xxxx/laplacian.py", line 50, in <module>
lap_single.norm().sum().backward()
File "xxxx//torch/_tensor.py", line 396, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File "xxxx//torch/autograd/__init__.py", line 173, in backward
Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
RuntimeError: Tensors of type SparseTensorImpl do not have strides
I find that it is the total_weight causes this error. So I have to give up the usage of taubin_smoothing. I replace the taubin_smoothing with the original Laplacian smoothing.
Again, go to pytorch3d/ops/mesh_filtering.py taubin_smoothing. ADD:
from pytorch3d.ops import laplacian
and Change the loop code in def taubin_smoothing:
for _ in range(num_iter):
L = laplacian(verts, edges)
verts = verts + torch.sparse.mm(L, verts)
Note that, the num_iter should set to 3 or 5, not to large.
🐛 Bugs / Unexpected behaviors
When I try to use Pytorch3d as a differential operator to do some operation like the taubin_smoothing, if the vertices of the mesh require the grad, then the error ouccrs.
Instructions To Reproduce the Issue:
The code to Reproduce the Issue is uploaded as BUG.zip.
And I also write it here:
The bug logs:
Solution
I look the code in pytorch3d/ops/mesh_filtering.py taubin_smoothing.
It seems that view(-1, 1) causes the error. So I make a small change as follows:
Then it works.
May it can help you.