How to optimize camera and light parameters in pytorch3d?

I want to optimize the light and camera parameters in pytorch3d, but find them to be defined at initial state, so how can I optimize them iteratively ?
for example, the camera is defined as follows:

def SfMPerspectiveCameras(
    focal_length=1.0, principal_point=((0.0, 0.0),), R=_R, T=_R, device="cpu"
):
    """
    SfMPerspectiveCameras has been DEPRECATED. Use PerspectiveCameras instead.
    Preserving SfMPerspectiveCameras for backward compatibility.
    """

    warnings.warn(
        """SfMPerspectiveCameras is deprecated,
        Use PerspectiveCameras instead.
        SfMPerspectiveCameras will be removed in future releases.""",
        PendingDeprecationWarning,
    )

    return PerspectiveCameras(
        focal_length=focal_length,
        principal_point=principal_point,
        R=R,
        T=T,
        device=device,
    )

then the focal_length and principal_point can not be learned by optimization.

1 Like

I don’t know, if any PyTorch3D devs are here in this board (I cannot find Nikhila or Jeremy), so I would recommend to create an issue on their github.

1 Like

@Tony_Lee for SfMPerspectiveCameras their wanted to ensure that R_absolute had valid rotation matrix, so they used an exponential map (implemented with so3_exponential_map ) of the axis-angle representation of the rotation log_R_absolute .

The boundle adjustment could be solved by recovered up to an unknown global rigid transformation g glob∈SE(3). Thus, for simplicity, they assumed knowledge of the absolute extrinsics of the first camera g0. They set g0 as a trivial camera g0=(I,0⃗ ) to work for simple rigid tranformation, but now that will change soon.

In order to be able to initialize the parameters you will need to use init for the class, .self and all the proper constructors. I am sure it will be fixed soon as they mentioned.

change to this class

class SfMPerspectiveCameras(CamerasBase): 
     def __init__(
        self,
        focal_length=1.0,
        principal_point=((0.0, 0.0),),
        R=_R,
        T=_T,
        device="cpu",
        image_size=((-1, -1),),
    ):

Hope it helps.

1 Like