# 深度度量学习

深度度量学习训练深度神经网络，将输入映射到一个嵌入空间中，使得该空间中的距离能够反映语义相似度，从而检索、验证和聚类都归结为度量嵌入向量之间的距离。网络学习一个嵌入函数 \(\phi\)，输入之间的相似度通过 \(d_{\phi}(x_i, x_j) = d(\phi(x_i), \phi(x_j))\) 计算，其中 \(d\) 为预定义的距离；输出通常被归一化到实超球面 \(S_D\) 上以进行正则化。<sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 嵌入函数 \(\phi\)；相似度为 \(d(\phi(x_i), \phi(x_j))\)，通常在超球面 \(S_D\) 上 <sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup> |
| FaceNet 结果 | 在 Labeled Faces in the Wild 上达到 99.63%，在 YouTube Faces DB 上达到 95.12%，每张人脸 128 字节<sup>[2](https://doi.org/10.48550/arxiv.1503.03832)</sup> |
| 元组成本 | 可能的三元组数量随数据集规模以 \(O(N^3)\) 增长，促使了采样方法和代理方法的出现<sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup><sup> • </sup><sup>[3](https://openaccess.thecvf.com/content_ICCV_2017/papers/Movshovitz-Attias_No_Fuss_Distance_ICCV_2017_paper.pdf)</sup> |
| 标准基准 | Stanford Online Products：120,053 张图像，22,634 个类别；其中 59,551 张图像 / 11,318 个类别用于训练<sup>[4](https://cvgl.stanford.edu/papers/song_cvpr16.pdf)</sup> |
| 采样效果 | 在 CUB-200-2011 上，随机采样的三元组损失达到 58.48 ± 0.31 的 Recall@1，而距离加权采样的间隔损失达到 63.09 ± 0.46<sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup> |
| 报告增益被夸大 | 许多论文声称相对于对比损失取得了超过 100% 的相对提升，这被追溯到 2016 年薄弱的基线<sup>[5](https://arxiv.org/pdf/2003.08505)</sup> |

## 工作原理

训练通过损失函数直接塑造嵌入空间的几何结构。对比损失作用于成对样本：它使正样本对之间的距离 \(d_p\) 小于阈值 \(m_{pos}\)，使负样本对之间的距离 \(d_n\) 大于阈值 \(m_{neg}\)。<sup>[5](https://arxiv.org/pdf/2003.08505)</sup> 一种常见形式为 \(\mathcal{L}_{\text{contrast}} = \mathbb{1}_{y_1 = y_2} \mathcal{D}^2 + \mathbb{1}_{y_1 \ne y_2} \max(0, \alpha - \mathcal{D}^2)\)，其中 \(\mathcal{D}\) 为嵌入距离。<sup>[6](https://hav4ik.github.io/articles/deep-metric-learning-survey/)</sup> 三元组损失则使用一个锚点、一个正样本和一个负样本，写作 \(\mathcal{L}_{\text{triplet}}(x, y, z) = [d(x, y) + M - d(x, z)]_+\)：它使锚点-正样本距离比锚点-负样本距离小一个间隔 \(M\)。<sup>[3](https://openaccess.thecvf.com/content_ICCV_2017/papers/Movshovitz-Attias_No_Fuss_Distance_ICCV_2017_paper.pdf)</sup><sup> • </sup><sup>[5](https://arxiv.org/pdf/2003.08505)</sup> 两者的区别是结构性的：三元组损失强制要求同一个人的每对人脸与所有其他人脸之间保持间隔，而基于成对的损失则鼓励同一身份的所有人脸坍缩到一个点上。<sup>[2](https://doi.org/10.48550/arxiv.1503.03832)</sup> 基于三元组的目标仅在间隔被违反时优化相对距离，即当 \(d_{\phi}(x_a, x_n) - d_{\phi}(x_a, x_p) < \gamma\) 时。<sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup>

## 实现方法

从业者的工作流程有三个主要部分：有信息量的输入样本、网络架构和度量损失函数。<sup>[7](https://www.mdpi.com/2073-8994/11/9/1066)</sup> 骨干网络产生嵌入，通常归一化到超球面上。<sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup> 批次构建至关重要：可能的三元组数量以 \(O(N^3)\) 增长，因此穷举枚举不可行，<sup>[3](https://openaccess.thecvf.com/content_ICCV_2017/papers/Movshovitz-Attias_No_Fuss_Distance_ICCV_2017_paper.pdf)</sup> 而采样策略可以同时提高网络的成功率和训练速度。<sup>[7](https://www.mdpi.com/2073-8994/11/9/1066)</sup> 一旦简单样本对不再有帮助，难负样本挖掘能产生更具判别力的模型，因为简单的三元组对更新没有影响，只会浪费时间和资源。<sup>[7](https://www.mdpi.com/2073-8994/11/9/1066)</sup> FaceNet 的半难在线挖掘需要 1,800 张图像的小批量，且仍然很慢。<sup>[3](https://openaccess.thecvf.com/content_ICCV_2017/papers/Movshovitz-Attias_No_Fuss_Distance_ICCV_2017_paper.pdf)</sup> 评估指标因任务而异：图像聚类用 F1 和 NMI，图像检索用 Recall@R，[行人重识别](https://www.edgepedia.org/zh/person-re-identification)用排名准确率，人脸验证用准确率。<sup>[7](https://www.mdpi.com/2073-8994/11/9/1066)</sup>

## 起源

这一脉络始于布罗姆利（Bromley）及其同事（1994）的孪生网络，其中两个相同的子网络从两个签名中提取特征，一个连接神经元度量特征向量之间的距离；与存储表示的距离小于阈值的签名被接受，其余全部作为伪造品拒绝。随后一篇 2005 年的 CVPR 论文将孪生架构应用于人脸验证，训练模型使得同人样本对的输出向量彼此接近、不同人样本对的输出向量彼此远离，将输入映射到一个目标空间，其 L-范数近似输入空间中的语义距离。<sup>[8](http://yann.lecun.com/exdb/publis/pdf/chopra-05.pdf)</sup> 三元组网络在 FaceNet 之前将三元组思想应用于深度度量学习。<sup>[9](https://ar5iv.labs.arxiv.org/html/1412.6622)</sup> 施罗夫（Schroff）、卡列尼琴科（Kalenichenko）和菲尔宾（Philbin）（2015）的 FaceNet 发表在 arXiv 上，用深度卷积网络和在线三元组挖掘为每张图像学习一个欧几里得嵌入。<sup>[2](https://doi.org/10.48550/arxiv.1503.03832)</sup> 提升结构化嵌入方法将批次中 \(O(m)\) 的成对距离向量提升为完整的 \(O(m^2)\) 成对矩阵，并引入了 Stanford Online Products 基准。<sup>[4](https://cvgl.stanford.edu/papers/song_cvpr16.pdf)</sup> 孙（Sohn）的多类 N 对损失出现在 NeurIPS 2016 上。

## 变体

基于成对的损失面临冗余训练对的多项式增长，导致收敛缓慢和随机采样下的模型退化，<sup>[10](https://arxiv.org/html/1904.06627)</sup> 训练复杂度为 \(O(M^2)\) 或 \(O(M^3)\)，其中 \(M\) 为训练数据量。<sup>[11](https://doi.org/10.48550/arxiv.2003.13911)</sup> 基于代理的方法被提出以克服这一有信息量样本对挖掘的瓶颈：它们通过一个或多个跨样本和批次共享的学习代表来近似每个类别的分布。<sup>[12](https://arxiv.org/html/2312.10046v1)</sup><sup> • </sup><sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup> Proxy-NCA 是第一个基于代理的损失，在一小组学习到的代理上优化 NCA 目标，消除了三元组采样的需要；代理作为模型参数的一部分被学习。<sup>[3](https://openaccess.thecvf.com/content_ICCV_2017/papers/Movshovitz-Attias_No_Fuss_Distance_ICCV_2017_paper.pdf)</sup> SoftTriple 为每个类别分配多个代理。<sup>[13](https://doi.org/10.48550/arxiv.1909.05235)</sup> Proxy-Anchor 将每个代理作为与批次中所有数据关联的锚点，结合了基于代理的速度和基于成对的数据间关系。<sup>[11](https://doi.org/10.48550/arxiv.2003.13911)</sup> 多相似度损失通过两步挖掘和加权方案联合考虑自相似度、正相对相似度和负相对相似度。<sup>[10](https://arxiv.org/html/1904.06627)</sup> 角度损失约束三元组三角形在负样本点处的角度，而非优化成对相似度，增加了尺度不变性和三阶几何约束。<sup>[14](https://openaccess.thecvf.com/content_ICCV_2017/papers/Wang_Deep_Metric_Learning_ICCV_2017_paper.pdf)</sup> 排序列表损失为每个查询使用所有正样本和负样本构建基于集合的结构，为每个类别学习一个超球面。<sup>[15](https://openaccess.thecvf.com/content_CVPR_2019/papers/Wang_Ranked_List_Loss_for_Deep_Metric_Learning_CVPR_2019_paper.pdf)</sup> 在人脸验证中，SphereFace、CosFace 和 ArcFace 分别应用乘性角度间隔、加性余弦间隔和加性角度间隔。<sup>[5](https://arxiv.org/pdf/2003.08505)</sup> 视觉 Transformer 进入了 DML 骨干网络：深度因子化度量学习（2023）用一个可学习的路由器对 DeiT-Small 骨干进行因子化，并在 CUB-200-2011、Cars196 和 SOP 上报告了最先进的结果。<sup>[16](https://openaccess.thecvf.com/content/CVPR2023/papers/Wang_Deep_Factorized_Metric_Learning_CVPR_2023_paper.pdf)</sup> OBD-SD 在训练期间而非推理期间应用在线批次扩散过程，减少谱衰减和过度聚类。<sup>[17](https://link.springer.com/article/10.1007/s44267-024-00051-0)</sup> 将 CLIP 文本嵌入与抗坍缩损失相结合，在 CUB200 上将 Recall@1 提高了 0.3%，在 Cars196 上提高了 0.4%，<sup>[18](https://arxiv.org/html/2407.03106)</sup> 而 UniME（2025）用多模态大语言模型学习通用多模态嵌入，展示了向基础模型嵌入的转变。<sup>[19](https://arxiv.org/abs/2504.17432v1)</sup> PD-Loss（2025）将可学习代理与可判别性指数 \(d'\) 相结合，避免了 \(O(N^2)\) 的批次内成对计算，并可在小至 32 的批次规模下工作。<sup>[20](https://arxiv.org/html/2508.17082)</sup>

## 应用

已部署的应用包括行人重识别、医学问题、3D 建模、人脸验证与识别以及签名验证。<sup>[7](https://www.mdpi.com/2073-8994/11/9/1066)</sup> 标准基准包括 CUB-200-2011（11,788 张图像，200 个鸟类类别，前 100 个类别用于训练）、Cars-196（16,185 张图像，198 个类别）和 Stanford Online Products。<sup>[4](https://cvgl.stanford.edu/papers/song_cvpr16.pdf)</sup> 在一致的评估协议下，广泛使用的目标函数表现出比文献所示高得多的性能饱和，报告的增益部分归因于不同的训练协议；Reality Check 分析发现，声称相对于对比损失超过 100% 的相对提升源于有缺陷的 2016 年提升结构基线，这些基线每批使用 \(N/2\) 个对、\(N/3\) 个三元组，且三元组间隔为 1 而非接近 0.1 的最优值。<sup>[5](https://arxiv.org/pdf/2003.08505)</sup><sup> • </sup><sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup> 在 ResNet50 骨干和 512 维嵌入下，批次内消息传递在 CUB-200-2011 上达到 70.3 的 Recall@1，在 Cars196 上达到 88.1，在 Stanford Online Products 上达到 81.4，在 In-Shop Clothes 上达到 92.8。<sup>[21](https://proceedings.mlr.press/v139/seidenschwarz21a/seidenschwarz21a.pdf)</sup> 基于势场的 DML 在 Cars-196 上以超过 5% 的 Recall@1 优于最佳基于代理的方法，在 CUB-200-2011 上超过 3.7%，在 SOP 上超过 1.5%。<sup>[22](https://openaccess.thecvf.com/content/CVPR2025/papers/Bhatnagar_Potential_Field_Based_Deep_Metric_Learning_CVPR_2025_paper.pdf)</sup>

## 局限与替代方案

挖掘策略带来昂贵的时间和内存成本，大批次规模受 GPU 内存限制；FaceNet 在 CPU 集群上运行挖掘以使用巨大的批次。<sup>[7](https://www.mdpi.com/2073-8994/11/9/1066)</sup> 批次采样使平均性能波动高达 1.5%，嵌入维度存在冗余：性能在 512 维达到峰值，在 1024 维下降。<sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup><sup> • </sup><sup>[23](https://openaccess.thecvf.com/content/ICCV2021/papers/Zheng_Deep_Relational_Metric_Learning_ICCV_2021_paper.pdf)</sup> 与分类式训练相比，ArcFace 类方法通过使用 \(W_j^T \cdot x_i = \|W_j\| \cdot \|\phi(x_i)\| \cdot \cos \phi_j\) 直接优化角度来最大化间隔；在 Google Landmarks 竞赛中，所有前 100 名参赛者都使用了 ArcFace 或 CosFace 变体。<sup>[1](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)</sup> 在标签错误的样本下，基于元组和基于代理的方法比势场模型退化得更严重。<sup>[22](https://openaccess.thecvf.com/content/CVPR2025/papers/Bhatnagar_Potential_Field_Based_Deep_Metric_Learning_CVPR_2025_paper.pdf)</sup>

## References

1. [Revisiting Training Strategies and Generalization Performance in Deep Metric Learning (Roth et al., ICML 2020)](https://proceedings.mlr.press/v119/roth20a/roth20a.pdf)
2. [Schroff, Florian, Kalenichenko, Dmitry, Philbin, James (2015). FaceNet: A Unified Embedding for Face Recognition and Clustering. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1503.03832)
3. [No Fuss Distance Metric Learning Using Proxies (Proxy-NCA, Movshovitz-Attias et al., ICCV 2017)](https://openaccess.thecvf.com/content_ICCV_2017/papers/Movshovitz-Attias_No_Fuss_Distance_ICCV_2017_paper.pdf)
4. [Deep Metric Learning via Lifted Structured Feature Embedding](https://cvgl.stanford.edu/papers/song_cvpr16.pdf)
5. [A Metric Learning Reality Check (Musgrave, Belongie, Lim; ECCV 2020)](https://arxiv.org/pdf/2003.08505)
6. [Deep Metric Learning: a (Long) Survey (blog by Chan Kha Vu)](https://hav4ik.github.io/articles/deep-metric-learning-survey/)
7. [Deep Metric Learning: A Survey (Kaya & Bilge, Symmetry 2019)](https://www.mdpi.com/2073-8994/11/9/1066)
8. [Learning a Similarity Metric Discriminatively, with Application to Face Verification](http://yann.lecun.com/exdb/publis/pdf/chopra-05.pdf)
9. [Deep metric learning using Triplet network](https://ar5iv.labs.arxiv.org/html/1412.6622)
10. [Multi-Similarity Loss with General Pair Weighting for Deep Metric Learning (Wang et al., CVPR 2019)](https://arxiv.org/html/1904.06627)
11. [Kim, Sungyeon and colleagues (2020). Proxy Anchor Loss for Deep Metric Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2003.13911)
12. [Deep Metric Learning for Computer Vision: A Brief Overview](https://arxiv.org/html/2312.10046v1)
13. [Qian, Qi and colleagues (2019). SoftTriple Loss: Deep Metric Learning Without Triplet Sampling. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1909.05235)
14. [Deep Metric Learning with Angular Loss (Wang et al., ICCV 2017)](https://openaccess.thecvf.com/content_ICCV_2017/papers/Wang_Deep_Metric_Learning_ICCV_2017_paper.pdf)
15. [Ranked List Loss for Deep Metric Learning (Wang et al., CVPR 2019)](https://openaccess.thecvf.com/content_CVPR_2019/papers/Wang_Ranked_List_Loss_for_Deep_Metric_Learning_CVPR_2019_paper.pdf)
16. [Deep Factorized Metric Learning (Wang et al., CVPR 2023)](https://openaccess.thecvf.com/content/CVPR2023/papers/Wang_Deep_Factorized_Metric_Learning_CVPR_2023_paper.pdf)
17. [Improving deep metric learning via self-distillation and online batch diffusion process (Visual Intelligence, Springer, 2024)](https://link.springer.com/article/10.1007/s44267-024-00051-0)
18. [Anti-Collapse Loss for Deep Metric Learning Based on Coding Rate Metric (arXiv 2024)](https://arxiv.org/html/2407.03106)
19. [UniME: Universal Embedding Learning with Multimodal LLMs (arXiv, Apr 2025)](https://arxiv.org/abs/2504.17432v1)
20. [PD-Loss: Proxy-Decidability for Efficient Metric Learning (arXiv, Aug 2025)](https://arxiv.org/html/2508.17082)
21. [Learning Intra-Batch Connections for Deep Metric Learning (Seidenschwarz et al., ICML 2021)](https://proceedings.mlr.press/v139/seidenschwarz21a/seidenschwarz21a.pdf)
22. [Potential Field Based Deep Metric Learning (Bhatnagar et al., CVPR 2025)](https://openaccess.thecvf.com/content/CVPR2025/papers/Bhatnagar_Potential_Field_Based_Deep_Metric_Learning_CVPR_2025_paper.pdf)
23. [Deep Relational Metric Learning (Zheng et al., ICCV 2021)](https://openaccess.thecvf.com/content/ICCV2021/papers/Zheng_Deep_Relational_Metric_Learning_ICCV_2021_paper.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › 机器学习与神经计算 › 神经网络与深度学习 › 标题：A至H

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/deep-metric-learning

English original: https://www.edgepedia.org/deep-metric-learning
