对于边框的预测是一个回归问题,通常可以选择平方损失函数(L2损失),但是这个损失函数对于比较大的误差的惩罚很高。我们可以采用稍微缓和一点绝对损失函数(L1)损失,它是随误差线性增长的,而不是平方增长。
但是这个函数在0点处的导数不为唯一,因此可能会影响收敛,一个通常的办法是在0点附近使用平方函数使得它更加平滑。我们称之为平滑L1损失。它通过一个参数sigma来控制平滑的区域。
smooth l1 loss损失 曲线
maskrcnn-benchmark中的实现:
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import torch
# TODO maybe push this to nn?
def smooth_l1_loss(input, target, beta=1. / 9, size_average=True):
"""
very similar to the smooth_l1_loss from pytorch, but with
the extra beta parameter
"""
n = torch.abs(input - target)
cond = n < beta
loss = torch.where(cond, 0.5 * n ** 2 / beta, n - 0.5 * beta)
if size_average:
return loss.mean()
return loss.sum()
参考:https://blog.youkuaiyun.com/wfei101/article/details/79809332