Hi all together,
I have problems with using the nn.MSELoss method for image classification: RuntimeError: bool value of Tensor with more than one value is ambiguous. Size of image and label are both (8, 104) - Do you have any ideas what the problem could be?
model = EasyNet()
optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.5)
for image, label in train_loader:
# Transfer to GPU
# image, label = image.to(device), label.to(device)
if image is None:
image = Variable(image)
label = Variable(label)
pred = model(image)
loss = nn.MSELoss(pred, label)
You are currently trying to pass
label to the initialization of
Use the functional API instead (
F.mse_loss) or initialize the criterion before using it:
criterion = nn.MSELoss()
loss = criterion(pred, label)
I chnge my loss unction from binary cross entropy to the torch.nn.CrossEntropyLoss
but it givee me this error "RuntimeError: bool value of Tensor with more than one value is ambiguous
The code is "
output = netD(real_cpu).view(-1)
label = torch.full((b_size,), real_label, device=device)
errD_real = criterion(output, label)
I don’t know, which line of code raises this particular error message, but
nn.CrossEntropyLoss expects class indices as the target, while you seem to use soft targets.
You could use this implementation for label smoothing.