In Defense of the Triplet Loss for Person Re-Identification

Alexander Hermans, Lucas Beyer, Bastian LeibearXiv 2017

Introduction

Person Re-Identification (ReID) is the task of matching individuals across non-overlapping camera views. It is fundamentally an "open-set" problem: the identities encountered during inference are entirely distinct from those seen during training. Consequently, the goal is to learn a robust embedding space where images of the same person are clustered together, while images of different people are separated.

Historically, the triplet loss was the intuitive choice for this task as it directly optimizes the relative distances between samples. However, the ReID community largely moved toward classification-based surrogate losses, citing the triplet loss as difficult to train, computationally expensive, and sensitive to the quality of "hard triplet mining." This paper challenges that shift, demonstrating that with a refined mining strategy and loss formulation, the triplet loss can outperform more complex state-of-the-art methods.

Methodology: Optimizing the Triplet Loss

The authors identify two critical components for successful metric learning in ReID: an efficient mining strategy and a continuous optimization objective.

Batch Hard Mining ($L_{BH}$)

Traditional triplet mining often involves searching the entire dataset for informative triplets, which is computationally prohibitive. The authors propose Batch Hard Mining. In this approach, each mini-batch is constructed by sampling $P$ identities and $K$ images per identity. For every anchor image in the batch, the loss is calculated using only the hardest positive (the most distant image of the same identity) and the hardest negative (the closest image of a different identity) within that specific batch. This strategy ensures that the model consistently receives a strong gradient from the most challenging local examples without the overhead of global mining.

Soft-Margin Formulation

Standard triplet loss uses a hinge function that stops providing a gradient once a fixed margin is satisfied. The authors replace this with a soft-margin formulation using the softplus function: $\ln(1 + \exp(\cdot))$. This encourages the network to continuously pull same-identity samples closer and push different-identity samples further apart, leading to more compact and discriminative clusters.

Table 1: Comparison of different triplet loss variants and margins. The Batch Hard strategy combined with a soft margin consistently yields the best performance.

Experimental Results

The proposed methods were evaluated using two architectures: TriNet (based on a pretrained ResNet-50) and LuNet (a smaller network trained from scratch).

Performance on Benchmarks

The results on major ReID benchmarks—Market-1501, MARS, and CUHK03—show that this simplified approach achieves top-tier results. On Market-1501, TriNet achieved a mean Average Precision (mAP) of 69.14%, significantly surpassing previous triplet-based implementations. On the MARS video dataset, it set a new state-of-the-art with 67.70% mAP.

Table 2: Comparison of TriNet and LuNet against state-of-the-art methods on Market-1501 and MARS datasets. TriNet achieves superior performance across all metrics.

Key Insights

  1. Mining Matters: As shown in the ablation studies, "Batch Hard" mining is significantly more effective than "Batch All" (averaging all possible triplets), as the latter is often diluted by easy, uninformative samples.
  2. Architecture Flexibility: While TriNet benefits from ImageNet pretraining, the custom LuNet architecture performs remarkably well. This suggests that for ReID, the loss function and mining strategy are often more critical than the specific choice of a large-scale pretrained backbone.
  3. Stability of Euclidean Distance: The authors found that using raw Euclidean distance rather than squared Euclidean distance leads to more stable training, likely due to more consistent gradient magnitudes.

Conclusion

By revisiting the triplet loss with modern training techniques, this work demonstrates that simple, well-tuned metric learning can outperform complex, multi-stage ReID pipelines. The "Batch Hard" strategy and soft-margin formulation provide a robust framework for learning discriminative embeddings, reaffirming the triplet loss as a powerful tool for open-set recognition tasks.

Summary updated

BibTeX
@misc{hermans2017defense,
  author = {Alexander Hermans and Lucas Beyer and Bastian Leibe},
  title = {{In Defense of the Triplet Loss for Person Re-Identification}},
  year = {2017},
  eprint = {1703.07737},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1703.07737},
}
Figure