Hello everybody, i am still trying to solve the issue i have explained here, i will leave it here for someone brave enough ![]()
Btw, I am trying to decompose my problem in order to understand why my parameters do not update and the gradient mantains as None.
Just to give you a little bit of context my model is (partially) defined as:
class Model(nn.Module):
def __init__(self, device, initial_rotation, initial_traslation, gs, gt, fov, pipe, bg):
super().__init__()
# device and gaussian splat
self.device = device
self.gaussian_splat = gs
self.criterion = nn.MSELoss()
# Target image
# self.image_ref = torch.from_numpy(gt).permute(2,0,1)
# self.image_ref = self.image_ref.to(self.device)
self.image_ref = PILtoTorch(gt, (472,837)).to(self.device)
# Parameters
self.r1 = nn.Parameter(
torch.from_numpy(initial_rotation[0]).to(self.device))
self.r2 = nn.Parameter(
torch.from_numpy(initial_rotation[1]).to(self.device))
self.r3 = nn.Parameter(
torch.from_numpy(initial_rotation[2]).to(self.device))
self.traslation = nn.Parameter(
torch.from_numpy(initial_traslation).to(self.device))
and this is a part of the forward method:
def forward(self):
R = torch.stack((self.r1, self.r2, self.r3))
world_view_transform = getWorld2View_custom(self.device, R, self.traslation).transpose(0, 1).to(self.device)
where getWorld2View_custom is defined as:
def getWorld2View_custom(device, R, t, translate=torch.tensor([.0, .0, .0]), scale=1.0):
Rt = torch.cat((torch.transpose(R, 0, 1), t.unsqueeze(1)), dim=1)
Rt = torch.cat((Rt, torch.tensor([[0, 0, 0, 1]], dtype=torch.float32, device=device).expand(1, 4)), dim=0)
C2W = torch.inverse(Rt)
cam_center = C2W[:3, 3] * scale
C2W[:3, 3] = cam_center
Rt = torch.inverse(C2W)
return Rt
R is given in the initialization of the model as a np.array with shape (3,3) and t as np.array with shape(3)
Do you think that torch.inverse operation lead to an interruption in the backpropagation?
I also printed the grad_fn of the result of this function world_view_trasform and i got <TransposeBackward0 object at 0x7fb0884e3070> which makes me think that is differentiable
Another question, is it right to suppose that if a tensor have a non None grad_fn then it is the product of differentiable operations in any case?