Stochastic smoothing of the top-K calibrated hinge loss for deep imbalanced classification

Camille Garcin, Alexis Joly, Joseph Salmon, Maximilien Servajean · OpenReview

Abstract

In modern classification tasks, the number of labels is getting larger and larger, as is the size of the datasets encountered in practice. As the number of classes increases, class ambiguity and class imbalance become more and more problematic to achieve high top-1 accuracy. Meanwhile, Top-K metrics (metrics allowing K guesses) have become popular, especially for performance reporting. Yet, proposing top-K losses tailored for deep learning remains a challenge, both theoretically and practically. In this paper we introduce a stochastic top-K hinge loss inspired by recent developments on top-K calibrated losses. Our proposal is based on the smoothing of the top-K operator building on the flexible "perturbed optimizer" framework. We show that our loss function performs very well in the case of balanced datasets, while benefiting from a significantly lower computational time than the state-of-the-art top-K loss function. In addition, we propose a simple variant of our loss for the imbalanced case. Experiments on a heavy-tailed dataset show that our loss function significantly outperforms other baseline loss functions.

Introduction

In many real-world scenarios—such as identifying rare plant species or specific bird types—achieving high "top-1" accuracy is nearly impossible due to the sheer number of classes and visual similarities between them. Instead, researchers use top-$K$ metrics, where a model is considered "correct" if the true label is among its top $K$ guesses.

However, training models to optimize this metric directly is difficult. Standard cross-entropy loss focuses on top-1 accuracy. Existing top-$K$ hinge losses often suffer from three major issues: non-smoothness and gradient sparsity, high computational complexity as $K$ increases, and poor performance on imbalanced "long-tailed" datasets.

Methodology: Stochastic Smoothing via Perturbation

The core innovation of this work is the Noised Balanced Top-$K$ Hinge Loss. Instead of finding a complex analytical smoothing for the top-$K$ operator, the authors inject Gaussian noise into the model's output scores (logits) and compute the top-$K$ values. By taking the expectation over this noise, the non-smooth top-$K$ function becomes a differentiable surface.

The standard top-K calibrated hinge loss (d) exhibits sharp ridges and non-smooth boundaries.
The proposed noised balanced loss (i) uses stochastic smoothing to create a differentiable surface.

Key Components

  • Stochastic Smoothing: The gradient is estimated using a Monte Carlo approach, sampling $B$ noise vectors. This allows the model to "explore" coordinates near the top-$K$ boundary during training.
  • Top-$K$ Calibration: The loss is built upon recent theoretical frameworks to ensure it is "calibrated," meaning minimizing this surrogate loss leads to the optimal top-$K$ classifier.
  • Uneven Margins for Imbalance: For imbalanced datasets, the authors introduce class-specific margins ($m_y$). Rare classes are assigned larger margins, forcing the model to be more confident about them to avoid high penalties. This is inspired by the Label-Distribution-Aware Margin (LDAM) loss.

Experimental Results

The researchers evaluated their approach on several benchmarks, including CIFAR-100, ImageNet, and the highly imbalanced Pl@ntNet-300K dataset (1,081 species).

Efficiency and Speed

On CIFAR-100, the proposed loss was significantly faster than the previous state-of-the-art (Berrada et al.). While the competitor's training time increased with $K$, the stochastic approach's computation time remained nearly flat, being roughly 25% faster at $K=5$.

Robustness and Imbalance

On the Pl@ntNet-300K dataset, the Noised Imbalanced loss achieved a macro-average top-1 accuracy of 42.4%, compared to 36.3% for cross-entropy and 40.6% for LDAM. The gains were most prominent in the "few-shot" classes at the tail of the distribution.

Discussion and Insights

  • Smoothing via Perturbation is Efficient: Unlike previous top-$K$ losses that scale poorly with $K$, the stochastic approach is practical for applications where $K$ might be large, such as recommendation systems.
  • Sparse Gradients aren't the Enemy: This paper shows that even with relatively sparse gradients, models can learn effectively as long as the smoothing allows for some exploration of nearby classes.
  • Calibration Matters: By starting with a top-$K$ calibrated hinge loss and smoothing it, the authors maintain better theoretical guarantees than previous "convex upper bound" approaches.

Conclusion

This paper introduces a stochastic top-$K$ hinge loss that is theoretically grounded, computationally efficient, and robust to class imbalance. By leveraging the perturbed optimizer framework, the authors provide a practical tool for fine-grained classification tasks. Future work includes extending this smoothing framework to other set-valued prediction tasks.

Summary updated

BibTeX
@misc{garcin2022stochastic,
  author = {Camille Garcin and Alexis Joly and Joseph Salmon and Maximilien Servajean},
  title = {{Stochastic smoothing of the top-K calibrated hinge loss for deep imbalanced classification}},
  year = {2022},
  eprint = {2202.02193},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2202.02193},
}
Figure