unsky / focal-loss

Focal loss for Dense Object Detection
483 stars 124 forks source link

Is this the correct formula for delta focal loss? #18

Open AlexeyAB opened 6 years ago

AlexeyAB commented 6 years ago

Hi @unsky Please, can you check, did I read your Focal Loss formulas correctly?

For CE, delta is:


For Focal Loss (when gamm=2), delta is:

Where are:

AlexeyAB commented 6 years ago

Or is it correct as written here? https://blog.csdn.net/linmingan/article/details/77885832

For Focal Loss (when gamm=2), delta is:

Because: float grad =-2*(1-output[ti])*logf(fmaxf(output[ti],0.0000001))*output[ti]+(1-output[ti])*(1-output[ti]);

Or the same: float grad = -2*(1-pt)*log(pt)*pt + (1-pt)*(1-pt) = (1-pt)*-2*pt*log(pt) + 1-pt)*(1-pt) = (1-pt)*(-2*pt*log(pt) + (1-pt)) = -1 * (1-pt)*(2*pt*log(pt) + pt - 1)