Skip to content

[Solved][PyTorch] RuntimeError: bool value of Tensor with more than one value is ambiguous

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())


References

4 thoughts on “[Solved][PyTorch] RuntimeError: bool value of Tensor with more than one value is ambiguous”

Leave a ReplyCancel reply

Click to Copy
Exit mobile version