其他分享
首页 > 其他分享> > RuntimeError: bool value of Tensor with more than one value is ambiguous

RuntimeError: bool value of Tensor with more than one value is ambiguous

作者:互联网

在使用nn.CrossEntropyLoss()损失函数时,报了错误:

RuntimeError: bool value of Tensor with more than one value is ambiguous

解决问题:

源代码是: 
loss = nn.CrossEntropyLoss(pred, target)

改正之后是:

loss = nn.CrossEntropyLoss()

val = loss(pred, target)

nn.CrossEntropyLoss() 是一个类,应该先行进行实例化。写代码时候粗心会导致这个错误,但是又不容易察觉出来。

 

 

标签:ambiguous,Tensor,nn,loss,pred,value,CrossEntropyLoss
来源: https://blog.csdn.net/Songerggggggg/article/details/112850754