Source-linked AI summary

Deep Metric Learning with Hierarchical Triplet Loss

Weifeng Ge, Weilin Huang, Dengke Dong, Matthew R. Scott

arXiv:1810.06951v1cs.CV

TL;DR

Random triplet sampling and mini-batch training limit deep metric learning by overlooking informative samples and global data distribution. HTL builds a class-level hierarchy and dynamically updates the violate margin to select hard samples with global context. It outperforms standard triplet loss on image retrieval and face recognition and achieves state-of-the-art results on several benchmarks.

  • Problem

    Random sampling and mini-batch training make it difficult for conventional triplet loss to focus on informative samples while considering global data distribution.

  • Method

    HTL constructs a class-level hierarchical tree encoding global context and computes a dynamic violate margin to collect meaningful hard triplets.

  • Results

    HTL significantly outperforms standard triplet loss on image retrieval and face recognition and achieves state-of-the-art performance on several standard benchmarks.

  • Takeaways & Limitations

    HTL encourages learning discriminative features from visually similar classes and can be integrated into standard triplet and other deep metric-learning losses.

Abstract

from arXiv · show

We present a novel hierarchical triplet loss (HTL) capable of automatically collecting informative training samples (triplets) via a defined hierarchical tree that encodes global context information. This allows us to cope with the main limitation of random sampling in training a conventional triplet loss, which is a central issue for deep metric learning. Our main contributions are two-fold. (i) we construct a hierarchical class-level tree where neighboring classes are merged recursively. The hierarchical structure naturally captures the intrinsic data distribution over the whole database. (ii) we formulate the problem of triplet collection by introducing a new violate margin, which is computed dynamically based on the designed hierarchical tree. This allows it to automatically select meaningful hard samples with the guide of global context. It encourages the model to learn more discriminative features from visual similar classes, leading to faster convergence and better performance. Our method is evaluated on the tasks of image retrieval and face recognition, where it outperforms the standard triplet loss substantially by 1%-18%. It achieves new state-of-the-art performance on a number of benchmarks, with much fewer learning iterations.

1 Introduction

Deep metric learning depends on informative correlated samples, but mini-batch training and random triplet sampling limit access to global data structure. HTL addresses this by using a hierarchical class tree and dynamically updated violate margins, improving discriminative learning and benchmark performance.

  • Deep metric learning losses learn embeddings by pulling same-class samples together and pushing different-class samples apart using correlated training samples.
  • Mini-batch optimization sees only local data distributions, making global context difficult to model and contributing to local optima and slow convergence.
  • HTL automatically collects informative triplets through a global class-level hierarchical tree that guides sampling.
  • HTL uses a dynamically computed violate margin to identify hard samples from visually similar but semantically different classes.
  • HTL integrates with standard triplet and other metric-learning losses, significantly outperforming standard triplet loss and achieving state-of-the-art benchmark results.

2 Related work

Deep metric learning maps images into feature spaces where distances represent visual similarity, while training must manage an infeasible number of pairs, triplets, and quadruplets under memory constraints. Prior work therefore relies on mini-batch construction and tuple-based losses.

  • Deep metric learning maps images to feature vectors in a manifold space where Euclidean or cosine distance measures similarity.
  • Contrastive, triplet, and quadruplet losses use correlated samples to pull same-class examples together and push different-class examples apart.
  • Informative Sample Selection: Training must sample from approximately O(N^2) pairs, O(N^3) triplets, and O(N^4) quadruplets because traversing all tuples is infeasible.
  • Informative Sample Selection: Large mini-batches can improve face-recognition training but are inconvenient for large-scale networks because of GPU-memory limitations.
  • Figure 1 contrasts triplets that violate the traditional triplet constraint with ignored triplets later revisited by hierarchical triplet loss.

3 Motivation: Challenges in Triplet Loss

Conventional triplet loss faces two linked challenges: random sampling produces many uninformative tuples, while mini-batch training misses global class structure. The paper motivates dynamic margins and structural class-tree sampling to focus learning on confusing classes.

  • 3.1 Preliminaries: Triplet loss forms anchor-positive-negative tuples whose labels satisfy y_a = y_p ≠ y_n and aims to separate different-label samples.
  • Challenge 1: triplet loss with random sampling: The constant violate margin determines which triplets produce hinge-loss gradients, making margin selection central to sample selection.
  • Challenge 1: triplet loss with random sampling: Randomly sampled triplets can converge slowly because most samples eventually obey the violate margin and contribute no gradients.
  • Challenge 2: risk of local optima: A structural class tree samples meaningful triplets by converting separation of hard samples into increasing distance between confusing classes, reducing the search space.
  • Challenge 2: risk of local optima: Mini-batch losses model similarity locally and cannot capture the whole data distribution, creating a risk of local optima even with hard-negative mining or re-weighting.

4 Hierarchical Triplet Loss

HTL builds a global class-level hierarchy from interclass distances and uses it to guide informative triplet sampling. A dynamically computed violate margin and anchor-neighbor sampling are integrated into iterative training with online tree updates.

  • 4.1 Manifold Structure in Hierarchy: The method constructs a class-level hierarchy that captures global data context by recursively merging classes according to interclass distances.Original image classes form leaf nodes; merging proceeds across levels using distance thresholds.
  • 4.1 Manifold Structure in Hierarchy: Interclass distances are computed from normalized deep features across all training samples, producing a distance matrix for the complete class set.The distance between classes p and q aggregates pairwise feature distances between their samples.
  • 4.1 Manifold Structure in Hierarchy: The hierarchy is updated interactively during training so that class relationships reflect the current model features.Algorithmically, the tree is rebuilt at each epoch using the current model.
  • 4.2 Hierarchical Triplet Loss: HTL replaces the conventional constant violate margin with a dynamic margin determined by the relationship between anchor and negative classes in the hierarchy.The margin uses the level where the two classes merge and the corresponding merging threshold, together with β = 0.1 and an anchor-class term.
  • 4.2 Hierarchical Triplet Loss: Anchor-neighbor sampling selects random anchor classes and their nearest classes, while triplets are formed from anchor, positive, and negative samples within each mini-batch.The training loop computes hierarchical margins, evaluates the loss, backpropagates gradients, and updates the tree during training.

5 Experimental Results and Comparisons

HTL is evaluated across image retrieval and face verification benchmarks, where it improves retrieval performance, generalizes across datasets, and accelerates convergence through hierarchical sampling.

  • 5.3 Cars-196 and Stanford Online Products: HTL achieves 81.4% Recall@1 on Cars-196 and 74.8% on Stanford Online Products, exceeding triplet loss by 2.2% on both datasets.
  • 5.4 LFW Face Verification: HTL shows inferior LFW verification performance compared with SphereFace at 99.42% and FaceNet at 99.65%.
  • 5.5 Sampling Matter and Local Optima: At 60% Recall@1, anchor-neighbor sampling with triplet loss and HTL converge about twice as fast as random sampling with batch size 480.
  • 5.5 Sampling Matter and Local Optima: HTL converges in 1000 iterations on CUB-200-2011, compared with 60000 iterations reported for HDC.
  • 5.6 Ablation Study: Ablations show dynamic violate margins improve Recall@1 from 75.3% to 78.9%, while the hierarchical tree raises it further to 80.9%.

6 Conclusion

The paper concludes that HTL selects informative triplets using an adaptively updated hierarchical tree encoding global context. Across image retrieval and face recognition, it achieves state-of-the-art results on standard benchmarks.

  • HTL selects informative triplets through an adaptively updated hierarchical tree that encodes global context.
  • The class-level hierarchy recursively merges visually similar classes, while a dynamically computed violate margin guides meaningful hard-sample selection.
  • HTL achieves new state-of-the-art performance on standard image retrieval and face recognition benchmarks.
Loading 1810.06951v1…