A Theoretically Sound Upper Bound on the Triplet Loss for Improving the Efficiency of Deep Distance Metric Learning

Thanh-Toan Do, Toan Tran, Ian D. Reid, B. G. Vijay Kumar, Tuan Hoang, Gustavo Carneiro

Introduction

Deep Distance Metric Learning (DML) is a fundamental task in computer vision, aimed at learning a feature space where similar objects are clustered together and dissimilar ones are pushed apart. The triplet loss has long been considered the gold standard for this task. However, it suffers from a significant computational bottleneck: for $N$ training samples, there are $O(N^3)$ possible triplets. This cubic complexity makes training on large-scale datasets notoriously slow and often necessitates complex, computationally expensive "mining" strategies to select informative samples.

The Proposed Discriminative Loss

To address these efficiency challenges, this paper introduces a new Discriminative Loss. This loss function acts as a theoretically sound, tight upper bound to the traditional triplet loss. Instead of the standard approach of comparing every point to every other point in a triplet (anchor, positive, negative), the authors propose a linearization of the problem using class centroids.

Comparison between standard triplet loss and the proposed upper bound using fixed centroids.

By leveraging the triangle inequality, the authors mathematically derive a loss that simultaneously pulls samples toward their own class centroid and pushes them away from all other class centroids. A key innovation is the use of fixed centroids on a unit hypersphere. Unlike previous "proxy-based" methods that require updating centroids via backpropagation—adding quadratic complexity—this method pre-defines centroids (using heuristics like one-hot vectors or K-means) and keeps them stationary throughout training. The neural network simply learns to map images into these pre-defined "slots."

Computational Efficiency

By fixing the centroids, the training complexity is reduced from $O(N^3)$ (or $O(N^2)$ for mining) to $O(NC)$, where $C$ is the number of classes. Since the number of classes is typically much smaller than the number of samples ($C \ll N$), the training process becomes essentially linear in the number of samples.

This theoretical reduction in complexity translates to massive real-world speedups. On the CUB-200-2011 dataset, the proposed method achieved a 12.5x speedup over "triplet with smart mining," reducing training time from 680 minutes to just 54 minutes. On the CAR196 dataset, the speedup reached approximately 17x.

Experimental Results and Generalization

Despite its simplicity and speed, the Discriminative Loss maintains competitive retrieval accuracy. Evaluated on standard DML benchmarks, the method achieved a Recall@1 of 51.43% on CUB-200-2011 and 68.31% on CAR196. These results outperform standard Softmax and several complex triplet-based variants, demonstrating that the theoretical upper bound is tight enough to serve as an effective proxy for the original triplet objective.

Furthermore, the method proved robust across different architectures, including GoogLeNet and VGG-16, indicating that its benefits are not tied to a specific backbone. By removing the need for margin tuning and complex mining strategies, the Discriminative Loss offers a streamlined and highly efficient path for large-scale distance metric learning.

Conclusion

This work provides a bridge between the theoretical robustness of triplet loss and the practical need for linear-time training. By re-framing DML as a mapping problem to fixed, well-distributed centroids, the authors have created a method that is both mathematically grounded and exceptionally fast, paving the way for more efficient open-world and life-long learning systems.

Summary updated

Abstract

We propose a method that substantially improves the efficiency of deep distance metric learning based on the optimization of the triplet loss function. One epoch of such training process based on a naive optimization of the triplet loss function has a run-time complexity O(N^3), where N is the number of training samples. Such optimization scales poorly, and the most common approach proposed to address this high complexity issue is based on sub-sampling the set of triplets needed for the training process. Another approach explored in the field relies on an ad-hoc linearization (in terms of N) of the triplet loss that introduces class centroids, which must be optimized using the whole training set for each mini-batch - this means that a naive implementation of this approach has run-time complexity O(N^2). This complexity issue is usually mitigated with poor, but computationally cheap, approximate centroid optimization methods. In this paper, we first propose a solid theory on the linearization of the triplet loss with the use of class centroids, where the main conclusion is that our new linear loss represents a tight upper-bound to the triplet loss. Furthermore, based on the theory above, we propose a training algorithm that no longer requires the centroid optimization step, which means that our approach is the first in the field with a guaranteed linear run-time complexity. We show that the training of deep distance metric learning methods using the proposed upper-bound is substantially faster than triplet-based methods, while producing competitive retrieval accuracy results on benchmark datasets (CUB-200-2011 and CAR196).
BibTeX
@inproceedings{do2019theoretically,
  author = {Thanh-Toan Do and Toan Tran and Ian D. Reid and B. G. Vijay Kumar and Tuan Hoang and Gustavo Carneiro},
  title = {{A Theoretically Sound Upper Bound on the Triplet Loss for Improving the Efficiency of Deep Distance Metric Learning}},
  booktitle = {CVPR},
  year = {2019},
  doi = {10.1109/cvpr.2019.01065},
}
Figure