Deep Metric Learning with Angular Loss

Jian Wang, Feng Zhou, Shilei Wen, Xiao Liu, Yuanqing Lin

TL;DR

Researchers from Baidu have introduced Angular Loss, a novel objective function for deep metric learning that replaces traditional distance-based constraints with geometric angular constraints. By focusing on the angle at the negative point of a triplet triangle, this method achieves scale invariance and captures higher-order relationships between data points, leading to state-of-the-art performance in image retrieval and clustering.

What Problem Does This Paper Address?

Deep metric learning aims to learn a feature space where similar images are close together and dissimilar ones are far apart. The "workhorses" of this field have long been contrastive loss (looking at pairs) and triplet loss (looking at an anchor, a positive, and a negative sample).

However, these distance-based losses face two major hurdles:

  1. Scale Sensitivity: Traditional triplet loss uses a fixed distance margin. This is problematic because different categories often have vastly different scales of intra-class variation. For example, as shown in Figure 1, the feature distribution for one car model might be much tighter than another, making a single global distance margin inappropriate.
  2. Limited Geometric Information: Distance only considers second-order information (the relationship between two points). This often leads to sub-optimal convergence because the optimization doesn't account for the local structure formed by the entire triplet simultaneously.
Figure 1. Example of feature embedding computed by t-SNE [32] for the Stanford car dataset [18], where the images of Ford Ranger SuperCab (right) have a more diverse distribution than Volvo C30 Hatchback (left). Conventional triplet loss has difficulty in dealing with such unbalanced intra-class variation. The proposed angular loss addresses this issue by minimizing the scale-invariant angle at the negative point.

Methods

The core contribution is the Angular Loss. Instead of pushing the negative point $x_n$ away from the anchor $x_a$ by a fixed distance $m$, the authors propose constraining the angle $\angle n$ at the negative point of the triangle formed by $(x_a, x_p, x_n)$.

The Geometry of the Loss

The goal is to ensure that $\angle n \leq \alpha$, where $\alpha$ is a predefined parameter. Intuitively, this forces the triplet to form a "skinny" triangle where the shortest edge connects the similar points ($x_a$ and $x_p$).

To make this stable during optimization—specifically to avoid cases where minimizing the angle might accidentally drag the negative point closer to the anchor—the authors reconstruct the triangle using a circumcircle passing through $x_a$ and $x_p$. This is illustrated in Figure 3, which shows how the reconstructed angle $\angle n'$ provides a more stable gradient.

Figure 3. Illustration of the angular constraint on a synthetic triplet where ∠a > 90◦. (a) Directly minimizing ∠n is unstable as it would drag xn closer to xa. (b) The more stable ∠n′ defined by re-constructing the triangle △mcn.

Implementation Details

  • N-pair Sampling: To maximize efficiency within a mini-batch, the authors adopt N-pair sampling, which allows a single anchor-positive pair to interact with multiple negative samples simultaneously.
  • Combined Loss: The best results are achieved by combining Angular Loss with the existing N-pair loss, creating a robust objective that benefits from both distance and angular constraints.

Datasets

The authors evaluated their method on three standard benchmarks for fine-grained recognition and retrieval:

  • CUB-200-2011: 200 bird species (11,788 images).
  • Stanford Car: 196 car classes (16,185 images).
  • Online Products: A large-scale e-commerce dataset with 22,634 classes (120,053 images).

Key Insights and Ideas

  • Scale Invariance: Because angles are invariant to scaling and rotation, the loss is naturally robust to variations in the local feature map. This allows the model to handle classes with different "spreads" in the embedding space more effectively.
  • Third-Order Constraints: The gradient for Angular Loss considers the interaction of all three points (anchor, positive, negative) at once. This captures the local structure of the triplet more precisely than traditional methods.
  • Meaningful Hyperparameters: Choosing an angle $\alpha$ is often more intuitive for researchers than choosing an arbitrary distance margin $m$, as $\alpha$ has a concrete geometric interpretation.

Key Results

The proposed method, particularly the combination of N-pair and Angular Loss (NL&AL), consistently outperformed baselines like standard Triplet Loss and Lifted Structure.

  • CUB-200-2011: Achieved a Recall@1 of 54.7%, compared to 51.9% for N-pair loss alone.
  • Stanford Car: Reached a Recall@1 of 71.4%, significantly higher than the 68.9% achieved by N-pair loss.
  • Online Products: Achieved a Recall@1 of 70.9%, a notable jump from the 66.9% baseline.

Qualitatively, the method produces much tighter clusters. As seen in Figure 6, the t-SNE visualization shows that even with large pose and appearance variations, the model generates compact feature mappings that preserve semantic similarity.

Figure 6. Visualization of feature embedding computed by our method (NP&AL) using t-SNE on the CUB-200-2011 dataset.

Limitations and Future Work

The authors identify two primary directions for future research:

  • Higher-Order Geometry: While this paper moves from second-order (distance) to third-order (triangles/angles), the authors suggest exploring fourth-order relations, such as constructing triangular pyramids from quadruplets and constraining the angles between edges and planes.
  • Integration with Other Tricks: The current study focused purely on the loss function. The authors note that combining Angular Loss with other practical techniques, like advanced hard negative mining or global clustering frameworks, could yield even further gains.

Summary updated

BibTeX
@inproceedings{wang2017deep,
  author = {Jian Wang and Feng Zhou and Shilei Wen and Xiao Liu and Yuanqing Lin},
  title = {{Deep Metric Learning with Angular Loss}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2017},
  url = {https://openreview.net/forum?id=HyELe-zO-H},
}
Figure