Class-Balanced Loss Based on Effective Number of Samples.

Yin Cui, Menglin Jia, Tsung-Yi Lin, Yang Song, Serge J. Belongie · DOI

TL;DR

This paper tackles the challenge of "long-tailed" datasets in machine learning, where a few classes dominate while most have very few examples. They propose a novel "class-balanced loss" that re-weights training samples based on an "effective number of samples," accounting for data overlap. This approach significantly improves performance on imbalanced datasets across various tasks and architectures.

What Problem Does This Paper Address?

Modern computer vision relies heavily on large datasets. However, real-world datasets often exhibit a "long-tailed" distribution, meaning a few classes have abundant data (the "head"), while the vast majority have very few examples (the "tail"). Training models on such imbalanced data leads to poor performance on the under-represented tail classes, as the model becomes biased towards the majority classes. Existing solutions like re-sampling (oversampling minority classes or undersampling majority classes) and simple inverse class frequency re-weighting have limitations, such as overfitting or discarding valuable data. This paper aims to develop a more principled and effective way to re-balance losses for long-tailed distributions.

Methods

The core innovation is a theoretical framework to quantify the "effective number of samples" for a given class. Instead of treating each sample as an isolated point, the authors associate each sample with a small "neighboring region" to account for data overlap and the effects of data augmentation. This leads to a formula for the effective number of samples, $E_n = (1 - \beta^n) / (1 - \beta)$, where $n$ is the number of samples and $\beta$ is a hyperparameter related to the total possible unique data points in a class.

Based on this, they introduce a "class-balanced loss" by applying a weighting factor inversely proportional to this effective number of samples. This weighting factor is designed to be model-agnostic and can be integrated with various loss functions, such as softmax cross-entropy, sigmoid cross-entropy, and focal loss. The hyperparameter $\beta$ allows for a smooth transition between no re-weighting (when $\beta$ is small) and re-weighting by inverse class frequency (as $\beta$ approaches 1).

Datasets

The authors evaluated their method on several datasets:

  • Artificially created long-tailed CIFAR-10 and CIFAR-100: These were generated by manipulating the number of training samples per class to create imbalance factors ranging from 10 to 200.
  • iNaturalist 2017 and 2018: Real-world datasets with a natural long-tailed distribution, containing thousands of classes.
  • ImageNet (ILSVRC 2012): A large-scale dataset used to demonstrate the generalizability of their approach.

Key Insights and Ideas

  • Data Overlap Matters: The fundamental insight is that simply counting samples is insufficient for imbalanced datasets. The redundancy and similarity among samples (exacerbated by data augmentation) mean that adding more samples to a class yields diminishing returns.
  • "Effective" Sample Count: The concept of "effective number of samples" provides a more nuanced way to understand class representation, capturing the idea that not all samples contribute equally.
  • Smooth Re-weighting: The proposed class-balanced loss, controlled by the hyperparameter $\beta$, offers a flexible way to re-balance losses. It can smoothly interpolate between standard loss functions and inverse class frequency weighting, allowing for fine-tuning to specific dataset characteristics.
  • Universality: The class-balanced term is designed to be loss-agnostic and model-agnostic, making it a versatile tool that can be readily applied to existing deep learning pipelines.

Key Results

  • Significant Performance Gains: Across all tested datasets (CIFAR, iNaturalist, ImageNet), the class-balanced loss consistently improved performance compared to standard loss functions.
  • CIFAR-10 vs. CIFAR-100 Behavior: On CIFAR-10, larger values of $\beta$ (closer to 1) generally led to better results, suggesting that inverse class frequency weighting was more effective. Conversely, on the more fine-grained CIFAR-100, smaller $\beta$ values (e.g., 0.99) were optimal, indicating that a smoother re-weighting was preferred. This aligns with the idea that finer-grained datasets have more unique prototypes, thus a smaller $N$ and a smaller $\beta$.
  • Outperforming Softmax: On large-scale datasets like iNaturalist and ImageNet, the class-balanced focal loss significantly outperformed standard softmax cross-entropy, achieving comparable or better results with smaller models. For instance, ResNet-50 with class-balanced focal loss achieved comparable performance to ResNet-152 with softmax on iNaturalist.

Limitations and Future Work

  • Hyperparameter Tuning: While the class-balanced loss offers flexibility, finding the optimal $\beta$ still requires hyperparameter tuning, which can be dataset-dependent. The paper notes that $\beta=0.999$ and $\gamma=0.5$ (for focal loss) provided good general performance.
  • Theoretical Assumptions: The current framework makes simplifying assumptions about data overlap. The authors suggest future work could involve incorporating more sophisticated assumptions about data distribution or developing learning-based, adaptive methods for estimating the effective number of samples.
  • Understanding $\beta$: While the paper provides intuition, a deeper theoretical understanding of how $\beta$ relates to dataset characteristics (like granularity and augmentation strategies) could be beneficial.

Summary updated

BibTeX
@inproceedings{cui2019class,
  author = {Yin Cui and Menglin Jia and Tsung-Yi Lin and Yang Song and Serge J. Belongie},
  title = {{Class-Balanced Loss Based on Effective Number of Samples.}},
  booktitle = {CVPR},
  year = {2019},
  doi = {10.1109/cvpr.2019.00949},
}
Figure