如何选择总用中常用的损失函数?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1531个文字,预计阅读时间需要7分钟。
L1损失(L1Loss)计算输出和目标之间的绝对值差,并取平均值。使用PyTorch实现如下:
pythonimport torchimport torch.nn as nn
定义L1Lossl1_loss=nn.L1Loss(reduction='mean')
输出和目标output=torch.tensor([1.0, 2.0, 3.0])target=torch.tensor([1.5, 2.5, 3.5])
计算L1损失loss=l1_loss(output, target)print(loss)
L1范数损失 L1Loss
计算 output 和 target 之差的绝对值。
torch.nn.L1Loss(reduction='mean')
#reduction-三个值,none: 不使用约简;mean:返回loss和的平均值;sum:返回loss的和。默认:mean。
均方误差损失 MSELoss
计算 output 和 target 之差的均方差。
torch.nn.MSELoss(reduction='mean')
#reduction-三个值,none: 不使用约简;mean:返回loss和的平均值;sum:返回loss的和。默认:mean。
本文共计1531个文字,预计阅读时间需要7分钟。
L1损失(L1Loss)计算输出和目标之间的绝对值差,并取平均值。使用PyTorch实现如下:
pythonimport torchimport torch.nn as nn
定义L1Lossl1_loss=nn.L1Loss(reduction='mean')
输出和目标output=torch.tensor([1.0, 2.0, 3.0])target=torch.tensor([1.5, 2.5, 3.5])
计算L1损失loss=l1_loss(output, target)print(loss)
L1范数损失 L1Loss
计算 output 和 target 之差的绝对值。
torch.nn.L1Loss(reduction='mean')
#reduction-三个值,none: 不使用约简;mean:返回loss和的平均值;sum:返回loss的和。默认:mean。
均方误差损失 MSELoss
计算 output 和 target 之差的均方差。
torch.nn.MSELoss(reduction='mean')
#reduction-三个值,none: 不使用约简;mean:返回loss和的平均值;sum:返回loss的和。默认:mean。

