应用
# 1.计算绝对差总和:|0-1|^2+|1-1|^2+|2-1|^2+|3-1|^2=6
# 2.求平均: 6/4 =1.5
import torch
import torch.nn as nn
sample = torch.tensor([[1.,1.],[1.,1.]])
target = torch.tensor([[0.,1.],[2.,3.]])
criterion = nn.MSELoss()
loss = criterion(sample, target)
print(loss)
API
CLASS torch.nn.MSELoss(size_average=None, reduce=None, reduction: str = 'mean')
mean squared error (squared L2 norm)
参数 | 描述 |
---|---|
size_average (bool, optional) | |
reduce (bool, optional) | |
reduction (string, optional) | ‘none’ , ‘mean’ , ‘sum’,‘none’ |
参考:
https://pytorch.org/docs/stable/generated/torch.nn.MSELoss.html#torch.nn.MSELoss