facebookresearch / pytorch3d

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

How to initialize camera once when using multiple gpus? #357

Closed kalyo-zjl closed 3 years ago

kalyo-zjl commented 3 years ago

Hi, thanks for releasing the useful 3D tools pytorch3d. It is really helpful for my project. But I have some problems when using it, can you give me a favor?

I'm confused that can I only initialize SfMPerspectiveCameras once in init function, if the camera is fixed? I found that SfMPerspectiveCameras requires to pass device as a parameter, so should I init it in every forward pass, as well as rasterizer and shader?

by the way, I'm new to this area. I may wonder if I can already get face color or vertex color with lighting, how can I choose a plain shader? Another question is that if I need a differentiable render engine, does the following setting right?

    self.blend_params = BlendParams(sigma=1e-4, gamma=1e-4)
    self.raster_settings = RasterizationSettings(
        image_size=opt.input_res,
        blur_radius=0,
        faces_per_pixel=1,
    )

    rasterizer = MeshRasterizer(
            cameras=cameras,
            raster_settings=self.raster_settings
            )
    renderer = MeshRenderer(
        rasterizer=rasterizer,
        shader=SoftPhongShader(
            device=meshes.device,
            cameras=cameras,
            blend_params=self.blend_params,
        )
    )

@nikhilaravi

nikhilaravi commented 3 years ago

@kalyo-zjl please create separate issues for each separate question!

I found that SfMPerspectiveCameras requires to pass device as a parameter, so should I init it in every forward pass,

You can use cameras.to(device) to move the camera tensors to a different device.

I may wonder if I can already get face color or vertex color with lighting, how can I choose a plain shader?

If you want there to be a uniform color for each face you can use the HardFlatShader or SoftFlatShader. If you want each vertex to have a color and interpolate this across the face you can use the HardGouraudShader or SoftGouraudShader.

If I need a differentiable render engine, does the following setting right?

In your current setup you will need to change the blur_radius so it is > 0. We have several tutorials with example code for how to set up a renderer with PyTorch3D so you can use these as a reference.

kalyo-zjl commented 3 years ago

Thank you very much! @nikhilaravi