mkocabas / focal-loss-keras

Focal Loss implementation in Keras
MIT License
328 stars 74 forks source link

Nan problem for LOG #17

Open jganzabal opened 6 years ago

jganzabal commented 6 years ago

I guess I would be safe to add epsilon to the log. Something like: return -K.sum(alpha K.pow(1. - pt_1, gamma) K.log(K.epsilon()+pt_1))-K.sum((1-alpha) K.pow( pt_0, gamma) K.log(1. - pt_0 + K.epsilon()))

gulzainali98 commented 5 years ago

did you find the solution? i am getting nan loss

jganzabal commented 5 years ago

@gulzainali98 adding K.epsilon() fixed Nan

gulzainali98 commented 5 years ago

can this be used on simple classification? i.e i am using CelebA dataset. Image just have to be classified into 40 different classes there is no object detection.

roywang2011 commented 5 years ago

can this be used on simple classification? i.e i am using CelebA dataset. Image just have to be classified into 40 different classes there is no object detection.

did you fixed your problem? I add K.epsilon() and still get nan

Fellfalla commented 5 years ago

@roywang2011 you need to make sure pt_1 does not become 1 and pt_0 does not become 0 when using gamma<1.0. Clip both with K.epsilon().

abc1044 commented 3 years ago

I add K.epsilon(),and it works! :thumbsup: