A Two-Head Loss Function for Deep Average-K Classification

Camille Garcin, Maximilien Servajean, Alexis Joly, Joseph Salmon

Introduction

In traditional image classification, models are typically trained to predict a single label (top-1). However, real-world datasets, particularly in specialized domains like botany, often contain significant ambiguity. A single image may plausibly belong to multiple closely related species, making a rigid top-1 or even a fixed top-K approach suboptimal. This paper introduces a novel "two-head" loss function designed for Average-K classification, a flexible framework where the model returns a variable number of labels per image while maintaining a target average set size of $K$ across the dataset.

The Average-K Classification Paradigm

Average-K classification addresses the limitations of fixed-size output sets. In top-K classification, the model is forced to return exactly $K$ labels, which may be too many for unambiguous images and too few for highly complex ones. Average-K allows the model to adapt its output size based on its internal confidence: it can return a single label when certain and a larger set when faced with ambiguity, provided the global average remains $K$.

Figure 1: Example of likely classes for ambiguous plant images, illustrating the need for set-valued predictions in complex datasets like Pl@ntNet-300K.

Proposed Methodology: The Two-Head Loss

The researchers propose a two-head architecture to optimize for the Average-K objective without the computational overhead of previous methods. The architecture consists of two distinct components:

  1. SCCP Head (Set Candidate Classes Proposal): Trained with standard cross-entropy, this head identifies the most plausible candidate classes (distractors) for a given input.
  2. ML Head (Multi-Label): This head is trained using multi-label binary cross-entropy loss to refine the final set of predictions.

To enforce the Average-K constraint during training, the model employs a batch-level strategy. It identifies the top $(K-1) \times \text{BatchSize}$ most likely alternative classes across an entire batch (as predicted by the SCCP head) and treats them as "pseudo-positives" for the ML head. This dynamic selection allows the model to learn class ambiguities effectively without requiring massive memory buffers.

Experimental Evaluation

The method was evaluated on two benchmarks:

  • CIFAR-100: A standard baseline with 100 classes and low ambiguity.
  • Pl@ntNet-300K: A challenging dataset of 1,081 plant species characterized by a "long-tail" distribution and high visual similarity between species.

Key Findings

The proposed two-head loss ($\ell_{AVG-K}$) consistently outperformed standard cross-entropy ($\ell_{CE}$) and other specialized multi-label losses.

  • Accuracy Gains: On Pl@ntNet-300K with $K=10$, the model achieved an accuracy of 98.23%.
  • Few-Shot Performance: The most significant improvement was observed in rare classes (those with fewer than 20 training images). For $K=10$, the proposed method reached 75.75% accuracy, dramatically outperforming standard cross-entropy, which achieved only 46.58%.
  • Uncertainty Calibration: Unlike standard models that often exhibit over-confidence, the two-head approach provides a more "honest" assessment of uncertainty, leading to more useful and interpretable set sizes.

Conclusion

The two-head loss function provides a robust and scalable solution for Average-K classification. By leveraging batch-level statistics and a dual-head architecture, the model successfully navigates the trade-off between precision and recall in ambiguous datasets. Future work will focus on refining the theoretical calibration of the loss and exploring its application in other set-valued classification tasks.

Summary updated

BibTeX
@inproceedings{garcin2025two,
  author = {Camille Garcin and Maximilien Servajean and Alexis Joly and Joseph Salmon},
  title = {{A Two-Head Loss Function for Deep Average-K Classification}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2025},
  doi = {10.1109/wacv61041.2025.00715},
}
Figure