yolov5 代码解读 损失函数 loss.py

smooth_BCE

def smooth_BCE(eps=0.1): # https://github.com/ultralytics/yolov3/issues/238#issuecomment-598028441
    # return positive, negative label smoothing BCE targets
    return 1.0 - 0.5 * eps, 0.5 * eps

把one-hot label 转换为soft label,一般认为这样更容易work。

BCEBlurWithLogitsLoss

self.loss_fcn = nn.BCEWithLogitsLoss(reduction='none') # must be nn.BCEWithLogitsLoss()
这里reduction用none因为在forward里返回的时候取mean。

dx = pred - true  # reduce only missing label effects, false positive
# dx = (pred - true).abs()  # reduce missing label and false label effects
alpha_factor = 1 - torch.exp((dx - 1) / (self.alpha + 1e-4))
loss *= alpha_factor

刚开始看这几行非常confused,查了很久。

https://github.com/ultralytics/yolov5/issues/1030
这个issue里说减少false negative的影响,我觉得应该写错了,是减少false positive的影响。

false negative指gt有框而network没有predict到,这时候的weight应该要比较大才对。

d x ∈ [ − 1 , 1 ] dx\in [-1,1] dx[1,1],当 d x = 1 dx=1 dx=1 ,即 p r e d = 1 , t r u e = 0 pred=1,true=0 p

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值