The error is most likely raised by using a list
for the price_label
assuming these are the weights
:
def weighted_mse_loss(input, target, weight):
return (weight * (input - target) ** 2)
x = torch.randn(10, 10, requires_grad=True)
y = torch.randn(10, 10)
weight = torch.randn(10, 1).tolist()
loss = weighted_mse_loss(x, y, weight)
# TypeError: only integer tensors of a single element can be converted to an index
Could you transform them to a tensor as it should work based on my previous code snippet?