facebookresearch / pytorch3d

PyTorch3D is FAIR's library of reusable components for deep learning with 3D data
https://pytorch3d.org/
Other
8.7k stars 1.3k forks source link

pytorch3d.ops.marching_cubes.marching_cubes return all -1 vertices #1641

Closed wshinigamic closed 7 months ago

wshinigamic commented 1 year ago

🐛 Bugs / Unexpected behaviors

All vertices returned by pytorch3d.ops.marching_cubes.marching_cubes() have coordinates -1.

Instructions To Reproduce the Issue:

Code:

from pytorch3d.ops.marching_cubes import marching_cubes
from skimage.draw import ellipsoid

ellip_base = ellipsoid(50, 60, 16, levelset=True)
verts, faces = marching_cubes(torch.from_numpy(ellip_base).unsqueeze(0).float(), 0)
print(verts[0])

Output:

tensor([[-1., -1., -1.],
        [-1., -1., -1.],
        [-1., -1., -1.],
        ...,
        [-1., -1., -1.],
        [-1., -1., -1.],
        [-1., -1., -1.]])
Vezzp commented 9 months ago

I encountered the same problem. And it seems like that the problem exists only for CPU version of marching cubes as running the same example on CUDA produces correct vertices.

bottler commented 9 months ago

@Vezzp That's weird. We've had (and fixed) various problems with the cuda marching cubes recently. But the CPU code has been working the whole time as far as we knew. Can you provide an example? And maybe can you run an example from our tests?

Khoa-NT commented 8 months ago

I test with v0.7.5

import torch
from pytorch3d.ops.marching_cubes import marching_cubes, marching_cubes_naive
from pytorch3d.io import save_obj

from skimage import measure
from skimage.draw import ellipsoid

# Generate a level set about zero of two identical ellipsoids in 3D
ellip_base = ellipsoid(10, 60, 16, levelset=True)
ellip_base_pt = torch.from_numpy(ellip_base).unsqueeze(0).float() # (N, D, H, W)

### 1) Run on CPU naive
### Slower than 4) Run by skimage
verts_cpu_naive, faces_cpu_naive = marching_cubes_naive(ellip_base_pt, 0)
save_obj('marching_cubes_naive.obj', verts_cpu_naive[0], faces_cpu_naive[0])

### 2) Run on CPU with the code from CUDA
### --> Weird result
verts_cpu, faces_cpu = marching_cubes(ellip_base_pt, 0)
save_obj('marching_cubes_cpu.obj', verts_cpu[0], faces_cpu[0])

### 3) Run on CUDA with the code from CUDA --> Error: RuntimeError: expected scalar type Int but found Long
### https://github.com/facebookresearch/pytorch3d/issues/1679
# verts_cuda, faces_cuda = marching_cubes(ellip_base_pt.cuda(), 0)

### 4) Run by skimage
### --> Can't save the face with pytorch3D
verts_skimage, faces_skimage, normals_skimage, values_skimage = measure.marching_cubes(ellip_base, 0)
save_obj('marching_cubes_skimage.obj', torch.from_numpy(verts_skimage.copy()), torch.from_numpy(normals_skimage.copy()))

1) Run on CPU naive image

2) Run on CPU with the code from CUDA image image

4) Run by skimage image