Description
I want to render LineMod dataset models and datapoints using pytorch3d but I wasn't able to succeed so far can you help me to point out what part I'm doing wrong?
Thanks.
`import torch
import numpy as np
import matplotlib.pyplot as plt
from pytorch3d.io import load_ply
from pytorch3d.structures import Meshes
from pytorch3d.renderer import (
MeshRenderer, MeshRasterizer, SoftPhongShader, RasterizationSettings,
PointLights, PerspectiveCameras, TexturesVertex
)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
ply_path = "/home/alperenc/Projects/PoseDatasets/Datasets/lm/lm/models/obj_000001.ply"
verts, faces = load_ply(ply_path)
verts = torch.tensor(verts, dtype=torch.float32, device=device)
faces = torch.tensor(faces, dtype=torch.int64, device=device)
fixed_color = torch.tensor([[0.0, 0.0, 1.0]], dtype=torch.float32, device=device) # Blue color
textures = TexturesVertex(verts_features=fixed_color.expand(verts.shape[0], -1).unsqueeze(0))
mesh = Meshes(verts=[verts], faces=[faces], textures=textures)
R = torch.eye(3, device=device).unsqueeze(0)
T = torch.zeros(1, 3, device=device)
cameras = PerspectiveCameras(device=device, R=R, T=T)
lights = PointLights(device=device, location=[[0.0, 0.0, 3.0]])
raster_settings = RasterizationSettings(image_size=640, blur_radius=0.0, faces_per_pixel=1)
renderer = MeshRenderer(
rasterizer=MeshRasterizer(cameras=cameras, raster_settings=raster_settings),
shader=SoftPhongShader(device=device, cameras=cameras, lights=lights)
)
image = renderer(mesh)
image = image[0, ..., :3].cpu().numpy()
plt.imshow(image)
plt.axis("off")
plt.show()
`
Output is all blue image