Hey, I am doing keypoint detecion with heatmaps. Where i have x,y cordinates for each image and i made heatmaps for them. I want to use a MSE loss function, but i cant use it on heatmaps alone since the numbers are very low(-1,1). I wrote a custom loss function that gets the cordinates from each of the heatmpas and then i calculate the mse with the x and y cordinates. But i get this error:

RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn.

When i check to see if the variables are leafs, it says that the model output variable(predicted) is not a leaf. But when i use any other built in pyotrch loss function i dont have the same problem, even though it also says that the output is not a leaf.

def forward(self, predicted, true):
loss = nn.MSELoss()
loss = loss(predicted, true)
return loss

This works but as said since i am comparing two heatmaps the loss function is really low after the first epoch(0.048).