nn.CrossEntropyLoss()->nn.SoftmaxCrossEntropyWithLogits

问题描述:
在pytorch中,利用nn.CrossEntropyLoss()求取的loss值是一个tensor标量,但是利用mindspore中nn.SoftmaxCrossEntropyWithLogits()求取的loss值是一个矢量(因为batct_size是32,所以求得的loss也是一个32*1的矢量)
原因:
在pytorch中,nn.CrossEntropyLoss()的参数默认值reduction='mean',求取的是平均值;
而在mindspore中,nn.SoftmaxCrossEntropyWithLogits的参数默认值reduction='none'。
 
mindspore中
nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction ="mean")
pytorch中
nn.CrossEntropyLoss()
原文地址:https://www.cnblogs.com/loyolh/p/14870602.html