赞
踩
L o s s ( x , y ) = 1 N ∑ i ( ∣ x i − y i ∣ ) Loss(x,y)=\frac{1}{N} \sum_{i}( |x_i-y_i|) Loss(x,y)=N1i∑(∣xi−yi∣)
简单而言,就是两个向量的绝对值的误差。 默认求平均,可以设置为sum。
也是mean absolute error(MAE)
举例而言:
loss = nn.L1Loss()
'''
L1 Loss
'''
predict_ar = [0,2,3]
target_ar = [2,2,3]
input = torch.FloatTensor(predict_ar)
input.requires_grad = True
target = torch.FloatTensor(target_ar)
output = loss(input, target)
print(output)
结果则是0.667
这个也容易理解,则是平方误差。 mean squared error。
loss = nn.MSELoss()
'''
L1 Loss
'''
predict_ar = [0, 2, 3]
target_ar = [2, 2, 3]
input = torch.FloatTensor(predict_ar)
input.requires_grad = True
target = torch.FloatTensor(target_ar)
output
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。