Deep Metric Learning via Lifted Structured Feature Embedding

Hyun Oh Song, Yu Xiang, Stefanie Jegelka, Silvio Savarese

Abstract

Learning the distance metric between pairs of examples is of great importance for learning and visual recognition. With the remarkable success from the state of the art convolutional neural networks, recent works have shown promising results on discriminatively training the networks to learn semantic feature embeddings where similar examples are mapped close to each other and dissimilar examples are mapped farther apart. In this paper, we describe an algorithm for taking full advantage of the training batches in the neural network training by lifting the vector of pairwise distances within the batch to the matrix of pairwise distances. This step enables the algorithm to learn the state of the art feature embedding by optimizing a novel structured prediction objective on the lifted problem. Additionally, we collected Stanford Online Products dataset: 120k images of 23k classes of online products for metric learning. Our experiments on the CUB-200-2011, CARS196, and Stanford Online Products datasets demonstrate significant improvement over existing deep feature embedding methods on all experimented embedding sizes with the GoogLeNet network.

Introduction: The Efficiency Gap in Metric Learning

Metric learning is the process of teaching a neural network to map images into a high-dimensional space where semantic similarity is reflected by geometric distance. Ideally, images of the same object should cluster together, while images of different objects should be pushed apart. Traditionally, this has been achieved using contrastive loss (operating on pairs) or triplet loss (comparing an anchor to one positive and one negative example).

However, these methods are inherently inefficient. In a typical training mini-batch of $m$ images, there are $O(m^2)$ possible pairwise relationships. Standard triplet-based approaches only sample a tiny fraction of these, often missing the "hard negatives"—the dissimilar images that are currently mapped too close to the anchor. This leads to weak gradient signals and slow convergence, as the network rarely encounters the most challenging examples that define class boundaries.

Proposed Method: Lifting the Batch

The authors propose Lifted Structured Feature Embedding, a novel loss function that utilizes the entire dense matrix of pairwise distances within a mini-batch. Instead of selecting random triplets, the algorithm computes distances between all images in the batch simultaneously.

Key Technical Innovations:

  1. Dense Pairwise Matrix: By "lifting" the vector of pairwise distances into a full matrix, the algorithm can identify the hardest negatives available within the current batch for every positive pair.
  2. Smooth Optimization: Mining only the single hardest negative can lead to unstable training. The authors use a smooth upper bound (log-sum-exp formulation) to provide a gradient signal from all negative pairs within a certain margin, avoiding the "dead zone" problem where gradients vanish.
  3. Importance Sampling: To ensure mini-batches are informative, the method samples positive pairs and then actively adds their most difficult neighbors to the batch.

Datasets and Benchmarking

The paper evaluates the method on three key benchmarks, including a significant new contribution to the field:

  • CUB-200-2011: 200 species of birds.
  • CARS196: 196 types of cars.
  • Stanford Online Products: A major contribution of this paper, featuring ~120k images across 23k classes. This dataset is designed for "extreme classification" where there are many categories but very few images per category.

Results and Impact

Using a GoogLeNet backbone, the proposed method significantly outperformed existing deep metric learning approaches. On the new Stanford Online Products dataset, the method achieved a Recall@1 of ~62%, a massive jump over the ~45-48% seen with standard contrastive or triplet losses.

Qualitative image retrieval results on the Stanford Online Products dataset. The leftmost column shows the query image, followed by the top retrieved results.

The method also showed consistent improvements in clustering metrics (F1 and NMI) across all tested embedding sizes. Crucially, the model performed exceptionally well on "unseen" classes—categories not present during training—proving it learned a general concept of similarity rather than just memorizing labels.

Conclusion and Future Outlook

By treating a mini-batch as a dense matrix of information rather than a collection of independent triplets, this approach effectively automates hard negative mining. This leads to more efficient training and superior feature embeddings. While the method relies on seeing many examples at once—making it sensitive to batch size constraints—the results on large-scale datasets like Stanford Online Products demonstrate the power of structured prediction in visual metric learning.

Summary updated

BibTeX
@inproceedings{song2016deep,
  author = {Hyun Oh Song and Yu Xiang and Stefanie Jegelka and Silvio Savarese},
  title = {{Deep Metric Learning via Lifted Structured Feature Embedding}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2016},
  url = {https://openreview.net/forum?id=HJZibRZd-S},
}
Figure