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

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

Closed
wshinigamic opened this issue Sep 19, 2023 · 3 comments
Closed

Comments

@wshinigamic
Copy link

🐛 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
Copy link

Vezzp commented Dec 6, 2023

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
Copy link
Contributor

bottler commented Dec 6, 2023

@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
Copy link

Khoa-NT commented Jan 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants