NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medical image segmentation

Michael Yeung, Evis Sala, Carola-Bibiane Schönlieb, Leonardo Rundo

TL;DR

This paper introduces the "Unified Focal loss," a novel loss function designed to improve medical image segmentation accuracy, especially in cases where certain classes (like small lesions) are vastly underrepresented. By unifying and generalizing existing Dice and cross-entropy-based losses, their method achieves state-of-the-art results across multiple challenging datasets and segmentation tasks.

What Problem Does This Paper Address?

Medical image segmentation, the process of identifying and outlining specific structures within medical scans, is crucial for diagnosis and treatment planning. Deep learning models, particularly U-Net architectures, have become the go-to for this task. However, a significant challenge arises from class imbalance: medical datasets often contain a disproportionately large background area compared to the regions of interest (e.g., tumors, lesions). This imbalance can lead to models that are biased towards the majority class, resulting in poor segmentation of the underrepresented, but clinically important, structures. Existing loss functions, like cross-entropy and Dice loss, have varying degrees of success in handling this imbalance, and it's often unclear which to choose or how they relate to each other. This paper aims to provide a unified, robust, and more easily optimizable solution.

Methods

The core contribution is the Unified Focal loss, a hierarchical framework that generalizes existing loss functions. It builds upon the ideas of Focal loss (which down-weights easy examples) and Tversky loss (which balances false positives and negatives) to create a more flexible and powerful loss function.

Here's a breakdown of the key methodological aspects:

  • Hierarchical Classification: The authors categorize loss functions into distribution-based (like cross-entropy), region-based (like Dice), and compound losses. They show how many existing losses can be derived from a common framework.
  • Unified Focal Loss: This new loss function unifies the benefits of Dice and cross-entropy-based approaches. It introduces tunable parameters to:
  • Control the weighting of positive and negative examples (similar to Tversky's $\alpha$ and $\beta$).
  • Control the degree of focusing on hard-to-classify examples (similar to Focal loss's $\gamma$).
  • Control the relative weighting between the Dice-like and cross-entropy-like components.
  • Asymmetric vs. Symmetric Variants: They propose both symmetric and asymmetric versions. The asymmetric variant is particularly important as it allows for selective enhancement or suppression of specific classes, addressing the issue where focal parameters might negatively impact the learning of rare classes.
  • Hyperparameter Simplification: A key innovation is simplifying the optimization process. By grouping functionally equivalent hyperparameters and leveraging asymmetry, they reduce the number of critical hyperparameters to tune, making the Unified Focal loss easier to use in practice. They recommend specific values for these parameters based on empirical evidence.

Datasets

The authors evaluated their Unified Focal loss on five publicly available, class-imbalanced medical imaging datasets:

  • CVC-ClinicDB: Colonoscopy images for colorectal polyp segmentation (2D binary).
  • DRIVE: Retinal fundus images for vessel segmentation (2D binary).
  • BUS2017: Breast ultrasound images for tumor segmentation (2D binary).
  • BraTS20: Brain tumor segmentation dataset (3D binary, focusing on enhancing tumor).
  • KiTS19: Kidney tumor segmentation dataset (3D multi-class, segmenting kidney and tumor).

These datasets represent a variety of imaging modalities, segmentation tasks (2D/3D, binary/multi-class), and degrees of class imbalance.

Key Insights and Ideas

  • Unified Framework is Powerful: The paper convincingly demonstrates that a unified approach to loss functions can outperform individual, specialized losses. By combining the strengths of Dice and cross-entropy, they achieve better performance.
  • Asymmetry Matters for Rare Classes: The asymmetric variant of the Unified Focal loss was consistently superior. This highlights that simply applying a focal mechanism to all classes isn't always optimal; selectively focusing on or de-emphasizing specific classes is crucial for imbalanced segmentation.
  • Hyperparameter Tuning Can Be Simplified: The reduction in the number of critical hyperparameters for the Unified Focal loss is a significant practical advantage, making it more accessible and easier to implement than complex combinations of existing losses.
  • Loss Function Choice is Critical: The stark performance differences across loss functions underscore how vital the choice of loss function is for achieving good segmentation results, especially in challenging, imbalanced scenarios.
  • Dice Loss Gradient Instability: The paper notes that Dice loss can suffer from unstable gradients, particularly with highly imbalanced data, which can lead to suboptimal convergence. Their Unified Focal loss aims to mitigate this.

Key Results

  • State-of-the-Art Performance: The Unified Focal loss (particularly the asymmetric variant) consistently achieved the highest segmentation accuracy (measured by DSC and IoU) across all five datasets and segmentation tasks.
  • For example, on the CVC-ClinicDB dataset, it achieved a DSC of 0.909 ± 0.023.
  • On the BraTS20 dataset, it achieved a DSC of 0.787 ± 0.049.
  • On the KiTS19 dataset, it achieved a DSC of 0.943 ± 0.011 for kidney segmentation and 0.634 ± 0.079 for tumor segmentation.
  • Robustness to Class Imbalance: The Unified Focal loss demonstrated superior performance compared to other methods, especially on datasets with high class imbalance, such as KiTS19.
  • Improved Recall-Precision Balance: The method showed a better balance between recall and precision, crucial for avoiding both missed diagnoses (false negatives) and unnecessary interventions (false positives).
  • Stable Performance: The Unified Focal loss exhibited stable performance across a range of its key hyperparameter ($\gamma$), indicating it's not overly sensitive to fine-tuning.
  • No Significant Increase in Training Time: The authors note that applying the focal parameter adds negligible computational complexity, meaning training times are comparable to using simpler loss functions.

Limitations and Future Work

  • Limited Scope of Comparison: The authors acknowledge that they focused on a subset of popular Dice and cross-entropy-based losses. Other loss function classes, like boundary-based losses, were not included.
  • Multiclass Hyperparameter Tuning: It's not immediately clear how to optimally assign the $\gamma$ hyperparameter in multiclass scenarios. The current approach of treating all rare classes similarly might be suboptimal.
  • Generalization to State-of-the-Art Architectures: While they used U-Net variants, it would be beneficial to assess if the performance gains generalize to more advanced architectures like nnU-Net.
  • Complementing Other Methods: Future work could explore how the Unified Focal loss can complement or even replace sampling-based methods for handling class imbalance.
  • Further Exploration of Hyperparameters: Investigating different $\gamma$ values for individual classes in multiclass segmentation is a promising avenue.

Summary updated

BibTeX
@article{yeung2022unified,
  author = {Michael Yeung and Evis Sala and Carola-Bibiane Schönlieb and Leonardo Rundo},
  title = {{Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medical image segmentation}},
  journal = {Comput. Medical Imaging Graph.},
  year = {2022},
  doi = {10.1016/j.compmedimag.2021.102026},
}
Figure