pytorch3d icon indicating copy to clipboard operation
pytorch3d copied to clipboard

Unstable behavior when use OpenGLPerspectiveCameras with Pulsar

Open Angtian opened this issue 2 years ago • 3 comments

The output will change when run the Pulsar multiple time with OpenGLPerspectiveCameras given an same input. To reproduce the issue:

from pytorch3d.renderer import look_at_view_transform, PulsarPointsRenderer, PointsRasterizationSettings, PointsRasterizer, OpenGLPerspectiveCameras
from pytorch3d.utils import ico_sphere
from pytorch3d.structures import Pointclouds
import torch

mesh_ = ico_sphere(4)

verts = mesh_.verts_packed()

device = 'cuda'
image_size = (128, 128)

R, T = look_at_view_transform(5, 6, 20, device=device)


C = 3
camera = OpenGLPerspectiveCameras(device=device, fov=12.0)
raster_settings = PointsRasterizationSettings(
    image_size=image_size, 
    radius = 0.01,
    points_per_pixel = 5
)

R = torch.nn.Parameter(R, requires_grad=True)

verts = verts.to(device)
rgb = torch.rand((verts.shape[0], C)).to(device)
point_cloud = Pointclouds(points=[verts], features=[rgb])
point_cloud = point_cloud.to(device)

print(point_cloud.features_packed().shape)

renderer = PulsarPointsRenderer(
    rasterizer=PointsRasterizer(cameras=camera, raster_settings=raster_settings),
    n_channels=C
).to(device)


for i in range(10):
    images = renderer(point_cloud, gamma=(1e-3,),
                    bg_col=torch.zeros(C, dtype=torch.float32, device=device), 
                    znear=torch.Tensor([1]).to(device), 
                    zfar=torch.Tensor([10]).to(device),
                    R=R, T=T
                    )
    print(images.max())

The output I get:

torch.Size([2562, 3])
tensor(0.9985, device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0.6976, device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0.6976, device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0.6976, device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0.6976, device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0., device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0., device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0., device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0., device='cuda:0', grad_fn=<MaxBackward1>)
tensor(0., device='cuda:0', grad_fn=<MaxBackward1>)

My pytorch3d version: 0.6.1. Can anyone give some suggestion? Thanks!

Angtian avatar May 26 '22 21:05 Angtian

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 26 '22 05:06 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jul 28 '22 05:07 github-actions[bot]

same problem. any updates?

icoz69 avatar Sep 02 '22 09:09 icoz69