def test_mesh_renderer_to(self): """ Test moving all the tensors in the mesh renderer to a new device. """ device1 = torch.device("cpu") R, T = look_at_view_transform(1500, 0.0, 0.0) # Init shader settings materials = Materials(device=device1) lights = PointLights(device=device1) lights.location = torch.tensor([0.0, 0.0, +1000.0], device=device1)[None] raster_settings = RasterizationSettings( image_size=256, blur_radius=0.0, faces_per_pixel=1 ) cameras = FoVPerspectiveCameras( device=device1, R=R, T=T, aspect_ratio=1.0, fov=60.0, zfar=100 ) rasterizer = MeshRasterizer(cameras=cameras, raster_settings=raster_settings) blend_params = BlendParams( 1e-4, 1e-4, background_color=torch.zeros(3, dtype=torch.float32, device=device1), ) shader = SoftPhongShader( lights=lights, cameras=cameras, materials=materials, blend_params=blend_params, ) renderer = MeshRenderer(rasterizer=rasterizer, shader=shader) mesh = ico_sphere(2, device1) verts_padded = mesh.verts_padded() textures = TexturesVertex( verts_features=torch.ones_like(verts_padded, device=device1) ) mesh.textures = textures self._check_mesh_renderer_props_on_device(renderer, device1) # Test rendering on cpu output_images = renderer(mesh) self.assertEqual(output_images.device, device1) # Move renderer and mesh to another device and re render # This also tests that background_color is correctly moved to # the new device device2 = torch.device("cuda:0") renderer = renderer.to(device2) mesh = mesh.to(device2) self._check_mesh_renderer_props_on_device(renderer, device2) output_images = renderer(mesh) self.assertEqual(output_images.device, device2)
# Define the settings for rasterization and shading. # Refer to raster_points.py for explanations of these parameters. raster_settings = RasterizationSettings( image_size=opt.image_size, blur_radius=0.0, faces_per_pixel=5, # this setting controls whether naive or coarse-to-fine rasterization is used bin_size=None, max_faces_per_bin=None # this setting is for coarse rasterization ) renderer = MeshRenderer(rasterizer=MeshRasterizer( cameras=None, raster_settings=raster_settings), shader=HardFlatShader(device=device)) renderer.to(device) if opt.point_lights: template_lights = PointLights() else: template_lights = DirectionalLights() # pcl_dict = {'points': pointclouds.points_padded[0].cpu().numpy()} data_dict = { "cameras_type": '.'.join([ camera_sampler.camera_type.__module__, camera_sampler.camera_type.__name__ ]), "cameras_params": camera_params,