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