Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2023 Sep;10(5):051809.
doi: 10.1117/1.JMI.10.5.051809. Epub 2023 Jun 23.

Batch-balanced focal loss: a hybrid solution to class imbalance in deep learning

Affiliations

Batch-balanced focal loss: a hybrid solution to class imbalance in deep learning

Jatin Singh et al. J Med Imaging (Bellingham). 2023 Sep.

Abstract

Purpose: To validate the effectiveness of an approach called batch-balanced focal loss (BBFL) in enhancing convolutional neural network (CNN) classification performance on imbalanced datasets.

Materials and methods: BBFL combines two strategies to tackle class imbalance: (1) batch-balancing to equalize model learning of class samples and (2) focal loss to add hard-sample importance to the learning gradient. BBFL was validated on two imbalanced fundus image datasets: a binary retinal nerve fiber layer defect (RNFLD) dataset (n=7,258) and a multiclass glaucoma dataset (n=7,873). BBFL was compared to several imbalanced learning techniques, including random oversampling (ROS), cost-sensitive learning, and thresholding, based on three state-of-the-art CNNs. Accuracy, F1-score, and the area under the receiver operator characteristic curve (AUC) were used as the performance metrics for binary classification. Mean accuracy and mean F1-score were used for multiclass classification. Confusion matrices, t-distributed neighbor embedding plots, and GradCAM were used for the visual assessment of performance.

Results: In binary classification of RNFLD, BBFL with InceptionV3 (93.0% accuracy, 84.7% F1, 0.971 AUC) outperformed ROS (92.6% accuracy, 83.7% F1, 0.964 AUC), cost-sensitive learning (92.5% accuracy, 83.8% F1, 0.962 AUC), and thresholding (91.9% accuracy, 83.0% F1, 0.962 AUC) and others. In multiclass classification of glaucoma, BBFL with MobileNetV2 (79.7% accuracy, 69.6% average F1 score) outperformed ROS (76.8% accuracy, 64.7% F1), cost-sensitive learning (78.3% accuracy, 67.8.8% F1), and random undersampling (76.5% accuracy, 66.5% F1).

Conclusion: The BBFL-based learning method can improve the performance of a CNN model in both binary and multiclass disease classification when the data are imbalanced.

Keywords: class imbalance; convolutional neural networks; deep learning; retina fundus.

PubMed Disclaimer

Figures

Fig. 1
Fig. 1
Workflow of the BBFL algorithm.
Fig. 2
Fig. 2
Focal loss has a modulating factor (1p^i)γ that decreases the loss contribution of well-classified samples. Increasing the γ parameter focuses less on samples that were predicted correctly with high probability. Focal loss can be applied to both binary and categorical crosss entropy loss functions.
Fig. 3
Fig. 3
ROC plots (left) and PRC plots (right) comparing the class imbalance techniques for InceptionV3 (top), MobileNetV2 (middle), and ResNet50 (bottom) to discriminate positive and negative RNFLD cases. Both plot types were generated using the raw RNFLD predictions from the highest performing model from the five experiments.
Fig. 4
Fig. 4
GradCAM visualizations of four positive RNFLD samples. In each 2×2 grid, the top two CFP images were selected as “easy” and the bottom two as “difficult” in RNFLD interpretability. ROS and BBFL algorithms visually produce the most accurate heatmaps with the least heat variance. ROS, random oversampling.
Fig. 5
Fig. 5
t-SNE plots using output from final GAP layer of InceptionV3 for RNFLD detection: (a) BBFL, (b) cost-sensitive, (c) random oversampling, (d) focal loss, (e) balanced-batches, and (f) baseline t-SNE.
Fig. 6
Fig. 6
Confusion matrix comparing imbalance learning techniques to BBFL using the ResNet50 network (n=788). Results from multiclass glaucoma classification with fundus images graded as normal (0), mild (1), moderate (2), and severe (3).
Fig. 7
Fig. 7
Confusion matrix comparing imbalance learning techniques to BBFL using the MobileNetV2 network (n=788). Results from multiclass glaucoma classification with fundus images graded as normal (0), mild (1), moderate (2), and severe (3).
Fig. 8
Fig. 8
Confusion matrix comparing imbalance learning techniques to BBFL using the InceptionV3 network (n=788). Results from multiclass glaucoma classification with fundus images graded as normal (0), mild (1), moderate (2), and severe (3).

References

    1. Johnson J. M., Khoshgoftaar T. M., “Survey on deep learning with class imbalance,” J. Big Data 6(1), 27 (2019).10.1186/s40537-019-0192-5 - DOI
    1. Masko D., Hensman P., “The impact of imbalanced training data for convolutional neural networks,” Independent thesis basic level (bachelor’s degree) (2015). http://urn.kb.se/resolve?urn=urn:nbn:se:kth:diva-166451
    1. Van Hulse J., Khoshgoftaar T., Napolitano A., “Experimental perspectives on learning from imbalanced data,” in ICML ‘07: Proc. 24th Int. Conf. Mach. Learn., pp. 935–942 (2007).10.1145/1273496.1273614 - DOI
    1. Pham T. C., et al. , “Improving skin-disease classification based on customized loss function combined with balanced mini-batch logic and real-time image augmentation,” IEEE Access 8, 150725–150737 (2020).10.1109/ACCESS.2020.3016653 - DOI
    1. Chawla N., Japkowicz N., Kołcz A., “Editorial: special issue on learning from imbalanced data sets,” SIGKDD Explorations 6, 1–6 (2004).10.1145/1007730.1007733 - DOI