Last Updated on 2021-07-05 by Clay
This is very common error message in PyTorch.
RuntimeError: bool value of Tensor with more than one value is ambiguous
Usually it is the wrong use of Loss, for example, the predicted value is entered into “Class” by mistake. (So you can check your “loss function.”)
Let’s look a example.
This is my Loss function, and it looks okay, right? However, it is not.
nn.NLLLoss () is a Class, we need to create it as an object to input “predicted result” and “correct answer”.
But, what is the correct way?
This is the case, I need to be careful to warn myself not to make the same mistake again. So far, I have searched the Internet three or four times for this error.
(By the way, multi-class output only needs to use LogSoftmax() + NLLLoss())
thank you that saved me
You’re welcome =)
OMG… It was a so simple mistake… Thank you for sharing this!
Hope it can help. =)