facebookresearch / pytorch3d

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

get error: IndexError: tensors used as indices must be long, byte or bool tensors #1756

Closed sunshineywz123 closed 1 day ago

sunshineywz123 commented 6 months ago

device = torch.device("cuda:0")

import trimesh import torch

Read the PLY file using trimesh

mesh = trimesh.load_mesh("assets/bop/ycbv/models/obj_000001.ply") vertices = torch.FloatTensor(mesh.vertices) faces = torch.Tensor(mesh.faces) faces = faces.type(torch.int32) uv_coordinates = torch.FloatTensor(mesh.visual.uv)

vertices = vertices.to(device) faces = faces.to(device) uv_coordinates = uv_coordinates.to(device)

verts_uvs = uv_coordinates[None,...] faces_uvs = faces[None,...]

texture = transforms.ToTensor()(Image.open("assets/bop/ycbv/models/obj_000001.png")) texture = torch.unsqueeze(texture.to(device), 0) texture = torch.permute(texture, (0, 2, 3, 1))

from pytorch3d.renderer import TexturesUV tex = TexturesUV(maps=texture, faces_uvs=faces_uvs, verts_uvs=verts_uvs) meshes = Meshes(verts=[vertices], faces=[faces], textures=tex)

get error: IndexError: tensors used as indices must be long, byte or bool tensors

bottler commented 6 months ago

Can you try replacing the line

faces = faces.type(torch.int32)

with

faces = faces.type(torch.int64)

?

sunshineywz123 commented 6 months ago

.type(torch.int64)

when i render, get error:image_renderer(meshes_to_render, cameras=cameras) *** RuntimeError: expected scalar type Float but found Long

bottler commented 6 months ago

Can you paste your current code? The verts need to be float32, the faces int64