Issue
I am trying to train a neural network using Pytorch. I would like the loss function to be the MSE. I tried to use torch.nn.MSELoss
, however I get an error that I do not understand.
For example the following code gives me RuntimeError: Boolean value of Tensor with more than one value is ambiguous
import torch
import torch.nn as nn
model = torch.zeros(64)
model.requires_grad = True
target = torch.ones(64)
loss = nn.MSELoss(model, target)
Any help will be very much appreciated!
Solution
Please look in Pytorch docs: https://pytorch.org/docs/stable/generated/torch.nn.MSELoss.html
You need to create an MSELoss object before calling with the target and predictions.
loss = nn.MSELoss()
input = torch.zeros(64, requires_grad=True)
target = torch.ones(64)
output = loss(input, target)
Answered By - Ophir Yaniv
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.