Metric learning: cross-entropy vs. pairwise losses

Malik Boudiaf, Jérôme Rony, Imtiaz Masud Ziko, Eric Granger, Marco Pedersoli, Pablo Piantanida, Ismail Ben Ayed

Abstract

Deep Metric Learning (DML) has traditionally relied on pairwise losses that require complex sample mining strategies. This work demonstrates that standard cross-entropy (CE) loss is a powerful proxy for maximizing mutual information between labels and features. By establishing a theoretical bridge between discriminative and generative views of mutual information, we show that CE achieves state-of-the-art results on standard benchmarks without the need for specialized heuristics.

Introduction

Deep Metric Learning (DML) aims to map data into an embedding space where semantic similarity corresponds to geometric proximity. Historically, the field has been dominated by pairwise losses, such as Triplet or Contrastive loss. However, these methods face significant optimization challenges due to the $O(n^2)$ or $O(n^3)$ complexity of possible pairs or triplets, necessitating sophisticated "sample mining" strategies to identify informative examples.

This paper investigates whether the simpler cross-entropy (CE) loss, typically reserved for classification, can serve as an effective objective for metric learning. We reveal that CE is not merely a classification tool but a mathematically elegant way to optimize the underlying pairwise distance properties of the embedding space by maximizing mutual information.

Methodology and Notation

The authors establish a formal framework for analyzing DML objectives. The model consists of an encoder $\phi_W$ that maps input features $\mathcal{X}$ to an embedded space $\mathcal{Z}$, followed by a soft-classifier $f_\theta$ that maps embeddings to a probability distribution over $K$ classes.

Table 1: General notation and model definitions including random variables for data, embeddings, and predictions.

The core of the methodology involves the derivation of Pairwise Cross-Entropy (PCE). The authors prove that standard cross-entropy acts as an upper bound on this pairwise loss, effectively serving as a "Majorize-Minimize" algorithm. This allows for the efficient optimization of feature clustering without ever requiring explicit pair mining heuristics.

Theoretical Framework: The Mutual Information Bridge

The fundamental insight of this work is that both CE and pairwise losses are essentially trying to maximize the Mutual Information $I(\widehat{Z}; Y)$ between learned features and labels.

Table 2: Information-theoretic definitions used to bridge classification and metric learning objectives.

As shown in Table 2, the mutual information can be decomposed using entropy and conditional entropy. Pairwise losses typically adopt a generative view, focusing on shaping the distribution of features to form tight clusters. In contrast, cross-entropy adopts a discriminative view, ensuring that labels are easily predictable from the features. The authors demonstrate that several popular DML losses (e.g., Center, Contrastive, Multi-Similarity) can be decomposed into "tightness" (intra-class) and "contrastive" (inter-class) components that share a theoretical lineage with CE.

Empirical Evaluation

The proposed approach was evaluated on four standard DML benchmarks: CUB200-2011 (birds), Cars-196, Stanford Online Products (SOP), and In-Shop Clothes Retrieval.

The results indicate that a well-tuned cross-entropy loss consistently outperforms or matches complex, state-of-the-art DML methods. For instance, on the CUB200 dataset, CE achieved a 69.2% Recall@1, significantly exceeding the 65.7% achieved by the popular Multi-Similarity loss. These findings suggest that many recent advancements in the field may be attributable to improved training heuristics (e.g., data augmentation, learning rate schedules) rather than the inherent superiority of complex loss functions.

Conclusion and Limitations

Cross-entropy provides a robust, simple, and effective baseline for Deep Metric Learning. By maximizing mutual information through a discriminative lens, it avoids the computational overhead and instability of sample mining. However, CE is limited to scenarios where absolute labels are available and may face scalability issues in "extreme classification" tasks with millions of classes where the final linear layer becomes memory-prohibitive. Future research should adopt CE as a standard baseline to rigorously evaluate the added value of more complex metric learning objectives.

Summary updated

BibTeX
@misc{boudiaf2020metric,
  author = {Malik Boudiaf and Jérôme Rony and Imtiaz Masud Ziko and Eric Granger and Marco Pedersoli and Pablo Piantanida and Ismail Ben Ayed},
  title = {{Metric learning: cross-entropy vs. pairwise losses}},
  year = {2020},
  eprint = {2003.08983},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2003.08983},
}
Figure