文章目录
1. 论文
1.1 Label Smoothing
- https://arxiv.org/abs/1906.02629 When Does Label Smoothing Help?
- https://arxiv.org/abs/1701.06548 Regularizing Neural Networks by Penalizing Confident Output Distributions
- https://arxiv.org/abs/1706.04599 On Calibration of Modern Neural Networks
1.2 Focal Loss
https://arxiv.org/abs/1708.02002 Focal Loss for Dense Object Detection
标签平滑: 提高模型的泛化能力,对于未知域任务,分类任务,可以提高精度。
2. 代码实现
2.1 Label Smoothing loss function
class LabelSmoothingCrossEntropy(nn.Module):
def __init__(self, eps=0.1, reduction='mean'):
super(LabelSmoothingCrossEntropy, self).__init__()
self.eps = eps
self.reduction = reduction
def forward(self, output, target):
c = output.size()[-1]
log_preds = F.log_softmax(output, dim=-1)
if self.reduction=='sum':
loss = -log_preds.sum()
else:
loss = -log_preds.sum(dim=-1)
if self.reduction=='mean':
loss = loss.mean()
return loss*self.eps/c + (1-self.eps) * F.nll_loss(log_preds, target, reduction=self.reduction)
2.2 labels mooth+类别不均衡loss

本文介绍了两种用于提高模型泛化能力的损失函数:Label Smoothing和Focal Loss。Label Smoothing通过平滑标签分布减少过拟合,Focal Loss则针对类别不平衡问题,通过调整难易样本权重降低简单样本的影响。提供了PyTorch实现的代码示例。

381

被折叠的 条评论
为什么被折叠?



