richardaecn / class-balanced-loss

Class-Balanced Loss Based on Effective Number of Samples. CVPR 2019
MIT License
600 stars 68 forks source link

Nan values in focal loss #16

Open maferoaloaiza opened 3 years ago

maferoaloaiza commented 3 years ago

Hi, I am using your implementation of focal loss, and sometimes the value calculated is nan. I realized that it is due to the normalization in terms of positive samples in the batch since I am working with 3D data, and I can't have big batches. I have a very unbalanced dataset as well. That causes that some of my batches are composed of only negative samples, so the normalization ends up having a zero division. How would you recommend I perform the normalization in this case?

RaagaMadappa commented 2 years ago

Hi Did you find a solution for this? I am getting nan values too because my dataset is highly unbalanced and for all the batches there is atleast one 0 value in the samples per class list.