Deep Metric Learning with Spherical Embedding

Dingyi Zhang, Yingming Li, Zhongfei Zhang

TL;DR

Deep Metric Learning (DML) often relies on angular distances to compare images, but this approach frequently ignores a critical detail: the length (or norm) of the embedding vectors. This paper introduces the Spherical Embedding Constraint (SEC), a simple yet powerful regularizer that forces embeddings onto the same hypersphere. This constraint leads to more balanced gradients, faster convergence, and state-of-the-art performance across various retrieval and recognition tasks.

What Problem Does This Paper Address?

The primary goal of Deep Metric Learning is to teach a neural network to map images into an "embedding space" where similar items are close together and different items are far apart. To achieve consistent results, researchers typically use angular distances (such as cosine similarity). This effectively decouples the direction of the vector (which represents the object's core features) from its magnitude (the "norm").

However, the authors highlight a hidden flaw in this standard practice: even if the loss function only evaluates the direction, the magnitude still dictates how the model learns. Mathematically, the gradient of an angular loss function is inversely proportional to the square of the embedding's norm.

This creates an "effective learning rate" problem. "Long" vectors update very slowly, while "short" vectors can jump around erratically. In standard training without constraints, these norms vary wildly, leading to unstable optimization, slower convergence, and sub-optimal feature representations.

Methods: The Spherical Embedding Constraint

To solve the instability caused by varying vector magnitudes, the authors propose the Spherical Embedding Constraint (SEC). Instead of letting embedding norms wander freely during training, SEC regularizes their distribution.

  • The Core Idea: SEC adaptively adjusts embeddings so they fall on the surface of the same hypersphere, ensuring consistent gradient updates across all samples.
  • Parameter-Free Target: Unlike previous methods that might force norms to a rigid, fixed constant (like 1.0), SEC pushes all embeddings in a mini-batch toward their average norm.
  • The Math: It adds a straightforward penalty term to the loss function: $L_{sec} = \frac{1}{N} \sum (||f_i||_2 - \mu)^2$, where $\mu$ is the mean norm of the current batch.
  • Plug-and-Play Compatibility: SEC is highly versatile. It can be seamlessly added to existing loss functions like Triplet Loss, Multi-Similarity Loss, or even Softmax-based losses used in face recognition.
Comparison of embedding norm distributions with and without SEC across CUB200-2011 and Cars196 datasets.

Datasets Evaluated

The authors evaluated SEC across three distinct domains to prove its versatility and robustness:

  1. Image Retrieval (Standard DML): CUB200-2011 (birds), Cars196 (cars), Stanford Online Products (SOP), and In-Shop Clothes Retrieval.
  2. Face Recognition: Models were trained on CASIA-WebFace and tested on LFW, AgeDB30, CFP-FP, and the massive MegaFace Challenge.
  3. Self-Supervised Learning: Evaluated using the SimCLR framework on CIFAR-10 and CIFAR-100.

Key Insights

  • Leveling the Playing Field: By proving that the embedding norm acts as a local multiplier for the learning rate, the authors show exactly why unconstrained norms are harmful. If one image has a norm of 10 and another has a norm of 1, the second image's direction will update 100 times faster. SEC eliminates this discrepancy.
  • Orthogonal Gradients: The paper demonstrates that for angular losses, the gradient is always orthogonal to the embedding itself. Optimization is therefore purely about rotating the vector to the correct direction, making uniform norms even more critical.
  • Superior to $L^2$ Regularization: Standard $L^2$ regularization blindly pushes norms toward zero. SEC is superior because it allows the model to find a "natural" scale for the embeddings (the batch mean) while simply ensuring consistency across samples.
  • Faster Convergence: By stabilizing the gradients, SEC allows models to reach peak performance in significantly fewer iterations compared to "vanilla" angular losses.

Key Results

SEC provided a consistent performance boost to almost every baseline it was tested against:

  • Metric Learning: On the CUB200 dataset, adding SEC to a standard Triplet Loss improved the Recall@1 score dramatically from 53.3% to 60.8%. It also provided noticeable gains even when paired with the state-of-the-art Multi-Similarity Loss.
  • Face Recognition: On the MegaFace benchmark (which includes 1 million distractors), SEC improved the rank-1 accuracy of popular models like ArcFace and CosFace by roughly 0.4% to 0.7%—a highly significant margin in the competitive face verification domain.
  • Self-Supervised Learning: When integrated into SimCLR, SEC improved top-1 accuracy on CIFAR-10 by over 2% in shorter training runs (100 epochs).

Limitations and Future Work

While the paper demonstrates robust and consistent results, there are a few areas ripe for further exploration:

  • Hyperparameter Sensitivity: While SEC is "parameter-free" regarding the target norm ($\mu$), it still introduces a scaling hyperparameter ($\eta$) to balance the constraint against the main loss. The authors show it is stable within a reasonable range (0.1 to 1.0), but it still requires dataset-specific tuning.
  • Theoretical Bounds: Future work could investigate if there is an "optimal" hypersphere radius that the model should converge to globally, rather than just relying on the moving batch mean.
  • Broader Impact: The authors briefly acknowledge the ethical controversies surrounding face recognition technology. While SEC improves algorithmic accuracy, it does not inherently solve broader societal issues like racial bias in AI training datasets.

Summary updated

BibTeX
@inproceedings{zhang2020deep,
  author = {Dingyi Zhang and Yingming Li and Zhongfei Zhang},
  title = {{Deep Metric Learning with Spherical Embedding}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2020},
}
Figure