PyTorch:损失函数
均方误差MSE
函数原型
1 | class torch.nn.MSELoss(size_average=None, reduce=None, reduction='mean') |
属性说明
- reduction
- = ‘none’:no reduction will be applied.下面的实例中,在loss1中是按照原始维度输出,即对应位置的元素相减然后求平方
- = ‘mean’(默认):the sum of the output will be divided by the number of elements in the output.
- = ‘sum’:the output will be summed.
Note:
size_average
andreduce
are in the process of being deprecated, and in the meantime, specifying either of those two args will override reduction.
1 | a = torch.tensor([[1, 2], |
评论