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

Learning with Average Precision: Training Image Retrieval with a Listwise Loss

Jérôme Revaud, Jon Almazán, Rafael Sampaio de Rezende, César Roberto de SouzaICCV 2019

Abstract

Image retrieval can be formulated as a ranking problem where the goal is to order database images by decreasing similarity to the query. Recent deep models for image retrieval have outperformed traditional methods by leveraging ranking-tailored loss functions, but important theoretical and practical problems remain. First, rather than directly optimizing the global ranking, they minimize an upper-bound on the essential loss, which does not necessarily result in an optimal mean average precision (mAP). Second, these methods require significant engineering efforts to work well, e.g., special pre-training and hard-negative mining. In this paper we propose instead to directly optimize the global mAP by leveraging recent advances in listwise loss formulations. Using a histogram binning approximation, the AP can be differentiated and thus employed to end-to-end learning. Compared to existing losses, the proposed method considers thousands of images simultaneously at each iteration and eliminates the need for ad hoc tricks. It also establishes a new state of the art on many standard retrieval benchmarks.

Introduction

Image retrieval is fundamentally a ranking task: given a query, the system must sort database images such that relevant ones appear at the top. Traditionally, deep learning models for this task rely on "local" losses, such as the triplet loss. These losses optimize a proxy—an upper bound on the essential loss—by looking at small groups of images (e.g., an anchor, a positive, and a negative).

However, local losses suffer from a metric mismatch, as minimizing triplet loss does not guarantee an optimal Mean Average Precision (mAP). Furthermore, they require complex engineering "tricks" like hard-negative mining and careful pre-training to be effective. This paper introduces a listwise loss function that allows a neural network to optimize for global ranking across thousands of images simultaneously, directly targeting the mAP metric.

Comparison between local triplet loss and the proposed global AP loss.

Methodology

The core contribution is a listwise loss that considers the entire ranking of a large batch of images at once, rather than isolated triplets.

Differentiable Average Precision

Average Precision (AP) is non-differentiable due to the sorting operation required for ranking. To overcome this, the authors employ histogram binning (soft-binning). Instead of hard-sorting images, similarity scores are "softly" assigned to discrete bins. This approximation makes the AP calculation smooth and differentiable, enabling end-to-end backpropagation.

Multistaged Backpropagation

Optimizing a listwise loss effectively requires very large batches (e.g., 4,096 images) and high-resolution inputs (800x800 pixels). Standard training would exceed GPU memory limits. To address this, a three-stage optimization strategy is implemented:

  1. Stage 1: A forward pass is performed for all images in "evaluation mode" to extract descriptors, discarding intermediate activations to save memory.
  2. Stage 2: The similarity matrix and the gradient of the loss with respect to the descriptors are computed.
  3. Stage 3: A second forward and backward pass is performed for each image individually, using the stored gradients from Stage 2 to accumulate weight updates.
The three-stage optimization strategy for training with large batches and listwise loss.

Experiments and Results

The models were trained on the Landmarks-clean dataset and evaluated on the Revisited Oxford (ROxford) and Revisited Paris (RParis) benchmarks, including the R1M distractor set.

Key Insights

  • Global Optimization: By processing thousands of images at once, the model naturally encounters hard negatives, eliminating the need for separate mining algorithms.
  • Simplicity and Stability: The method is robust to hyper-parameters, requiring only the batch size and the number of quantization bins. Performance remains stable even with as few as 20 bins.
  • Efficiency: The multistaged approach allows training on a single commodity GPU in approximately one day, which is significantly faster than traditional triplet-based pipelines.

Performance

The proposed "GeM (AP)" model established a new state-of-the-art. On the "Hard" protocol for ROxford and RParis, it outperformed previous best results by over 4 points in mAP. Notably, the model achieves these results starting from standard ImageNet initialization, without requiring specialized classification pre-training. It also demonstrates superior robustness when 1 million distractor images are added.

Conclusion

Directly optimizing Average Precision via a listwise loss simplifies the training pipeline for image retrieval while delivering superior performance. While the current method focuses on global descriptors, future work could integrate geometric verification for even higher precision. The framework also shows promise for other ranking-centric tasks such as person re-identification and object detection.

Summary updated

BibTeX
@inproceedings{revaud2019learning,
  author = {Jérôme Revaud and Jon Almazán and Rafael Sampaio de Rezende and César Roberto de Souza},
  title = {{Learning with Average Precision: Training Image Retrieval with a Listwise Loss}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2019},
  url = {https://openreview.net/forum?id=hU9uf4P9B8},
}
Figure