# 监督对比学习

监督对比学习（SupCon）是一种机器学习技术，它训练神经网络编码器将共享同一标签的样本表示拉近，同时将不同标签的样本推开，所使用的对比损失会考虑标签信息。它将自监督批次对比学习——其中正样本仅来自同一图像的增强视图——扩展到全监督设置，产生的嵌入中同类点簇紧凑、不同类簇分离。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> 学习到的表示通过下游线性分类器用于分类，该方法已应用于遗传学、分布外检测、目标检测、视频动作识别和神经科学。<sup>[2](https://openaccess.thecvf.com/content/CVPR2025/papers/Mildenberger_A_Tale_of_Two_Classes_Adapting_Supervised_Contrastive_Learning_to_CVPR_2025_paper.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 提出论文 | 霍斯拉、泰特瓦克、王、萨尔纳、田、伊索拉、马希诺、刘和克里希南，《监督对比学习》，2020<sup>[3](https://doi.org/10.48550/arxiv.2004.11362)</sup> |
| 损失结构 | 每个锚点有多个正样本和多个负样本；推广了三元组损失和 N 对损失<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> |
| ImageNet，ResNet-50 | top-1 准确率 78.7%，交叉熵为 78.2%；ResNet-200 达 81.4%<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> |
| CIFAR-10 / CIFAR-100 | 相比监督交叉熵（ResNet-50），分别为 96.0% 对 95.0% 和 76.5% 对 75.3%<sup>[4](https://github.com/hobbitlong/supcontrast)</sup> |
| 温度 | 所有报告结果均使用 \( \tau = 0.1 \)；最优温度可提升性能近 3%<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> |
| 批次大小 | 训练批次最高达 6144；大多数用途 2048 已足够<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> |
| 训练成本 | 约为交叉熵的 2 倍，因为多视图批次使有效批次翻倍<sup>[5](https://papers.nips.cc/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Review.html)</sup> |

## 工作原理

该方法建立在一个批次 \( N \) 个样本、\( C \) 个类别上的监督对比损失之上。每个锚点样本 \( i \) 有一个正样本集合 \( P(i) \)，即批次中所有与其共享标签的其他样本（包括同一图像的第二增强视图），以及一个包含除 \( i \) 外所有样本的集合 \( A(i) \)。设 \( z_i \) 为 L2 归一化嵌入，\( \tau \) 为温度，表现最佳的公式为

\[ \mathcal{L}_{out}^{sup} = \sum_{i \in I} \frac{-1}{|P(i)|} \sum_{p \in P(i)} \log \frac{\exp(z_i \cdot z_p / \tau)}{\sum_{a \in A(i)} \exp(z_i \cdot z_a / \tau)} \]

由霍斯拉及其同事给出。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> 第二个版本 \( \mathcal{L}_{in}^{sup} \) 将对正样本的平均放在对数内部；由于对数函数是凹函数，Jensen 不等式给出 \( \mathcal{L}_{in}^{sup} \le \mathcal{L}_{out}^{sup} \)，而外和版本在实践中表现最佳。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup>

监督损失将先前的对比目标作为特例包含在内：当正样本仅限于同一图像的视图时，它变为自监督对比损失；当只有一个正样本和一个负样本时，它呈现为间隔 \( \alpha = 2\tau \) 的三元组损失形式；当有一个正样本和多个负样本时，它等价于 N 对损失。<sup>[6](https://proceedings.neurips.cc/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Supplemental.pdf)</sup> 相比之下，在 SimCLR 的 NT-Xent 损失中，小批次中其他 \( 2(N-1) \) 个增强样本被视作每个正样本对的负样本，使用温度 \( \tau \) 和 L2 归一化嵌入；SupCon 的不同之处在于利用标签信息将同类样本视为正样本而非负样本。<sup>[7](https://arxiv.org/pdf/2002.05709v3.pdf)</sup>

其准确率背后的机制是几何的。格拉夫等人（ICML 2021）证明，一旦每个类的表示坍缩到内接于超球面的正单纯形顶点，交叉熵和监督对比损失均达到最小值；SupCon 训练的网络将类均值排列得比交叉熵更接近这一理想构型，因为该损失将批次视为具有成对样本交互的原子计算单元，而非逐样本作用。<sup>[8](https://proceedings.mlr.press/v139/graf21a.html)</sup> 其梯度结构还执行隐式难正样本和难负样本挖掘，消除了三元组损失所需的显式难样本挖掘。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> 使用标签作为正样本还避免了自监督对比学习的假阴性问题，即随机抽取的负样本可能来自与锚点相同的类，从而降低表示质量。<sup>[9](https://research.google/blog/extending-contrastive-learning-to-the-supervised-setting/)</sup>

## 实施方法

训练遵循两阶段协议。首先，每个输入批次增强两次获得两个副本，通过编码器网络传播产生 2048 维归一化表示；监督对比损失在应用于该表示的投影网络的输出上计算，该投影网络在预训练后丢弃。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> 其次，在冻结的表示上训练线性分类器，最少只需 10 轮。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup>

报告的设置给出了规模感：批次大小最高达 6144（大多数用途 2048 已足够），ResNet-200 预训练 700 轮，较小模型 350 轮，ImageNet 预训练使用 LARS 优化器，线性层使用 [RMSProp](https://www.edgepedia.org/zh/rmsprop)，CIFAR-10/100 上使用带动量的 SGD。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup> 官方实现为 Cloud TPU V3 上的 [TensorFlow](https://www.edgepedia.org/zh/tensorflow) v1，论文中的 CIFAR-10 数据来自单独的 PyTorch 实现。<sup>[10](https://github.com/google-research/google-research/tree/master/supcon)</sup>

## 起源

监督对比损失由 普拉奈·霍斯拉及其同事在《监督对比学习》中报告，2020 年发表于 arXiv。<sup>[3](https://doi.org/10.48550/arxiv.2004.11362)</sup> 它建立在自监督对比学习的前身之上：阿伦·范登奥尔德、李亚哲和奥里奥尔·维尼亚尔斯 的对比预测编码（2018）<sup>[11](https://doi.org/10.48550/arxiv.1807.03748)</sup> 以及 陈婷、西蒙·科恩布利思、穆罕默德·诺鲁齐和[杰弗里·辛顿](https://www.edgepedia.org/zh/geoffrey-hinton) 的 SimCLR（2020），SupCon 对其进行了推广。<sup>[12](https://doi.org/10.48550/arxiv.2002.05709)</sup>

## 变体

若干命名变体将该损失适配到原始公式表现不佳的设置中。

**监督 SimCLR。** 在官方代码中设置 \( \text{--use\_labels=False} \) 即可复现 SimCLR 风格的自监督对比学习，因为 SimCLR 是 SupCon 的一个特例，其中每个样本的标签在全局批次内唯一。<sup>[10](https://github.com/google-research/google-research/tree/master/supcon)</sup>

**TSC。** 目标监督对比学习，由李天宏及其同事（2021，arXiv）提出，将均匀分布在超球面上的预计算目标分配给类中心，改善长尾识别的特征分布均匀性。<sup>[13](https://doi.org/10.48550/arxiv.2111.13998)</sup>

**THANOS / Lspread。** 为对抗类坍缩，在 SupCon 中加入加权类条件 InfoNCE 损失和类条件自编码器，并引入散布损失 \[ \hat{\mathcal{L}}_{spread}(f,x,B) = (1-\alpha)\hat{\mathcal{L}}_{sup}(f,x,B) + \alpha\hat{\mathcal{L}}_{cNCE}(f,x,B) \]，由陈美仪及其同事（2022，arXiv）提出；这改善了迁移性和最差组鲁棒性。<sup>[14](https://doi.org/10.48550/arxiv.2204.07596)</sup>

**二类不平衡变体。** 对于二类不平衡数据，大卫·米尔登伯格及其同事（2025，arXiv）提出了监督少数类（在少数类上使用 SupCon 结合多数类上的 NT-Xent）和监督原型（在超球面两端固定类原型），相比标准 SupCon 将下游分类提升高达 35%。<sup>[15](https://doi.org/10.48550/arxiv.2503.17024)</sup>

**多标签损失。** 在多标签设置中，相似-不相似损失利用集合论相似性和不相似性因子动态重新加权正样本，当两个加权因子均为 1 时精确退化为 SupCon 损失，并在 MIMIC-III-Full 上报告了最先进的性能。<sup>[16](https://arxiv.org/html/2410.13439v5)</sup>

## 应用

SupCon 在多种架构和数据集上均优于交叉熵。使用 ResNet-50 时，CIFAR-10 达 96.0%（对比 95.0%），CIFAR-100 达 76.5%（对比 75.3%），ImageNet 达 78.7%（对比 78.2%）；使用 ResNet-200 时，ImageNet top-1 达 81.4%。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup><sup> • </sup><sup>[4](https://github.com/hobbitlong/supcontrast)</sup> 在相同设置下（批次 6144，ImageNet，ResNet-50）与 N 对损失相比，SupCon 达到 78.7% 对 57.4%。<sup>[6](https://proceedings.neurips.cc/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Supplemental.pdf)</sup> SupCon 模型在 ImageNet-C 上的平均腐蚀误差也低于交叉熵模型，且在增强、优化器和学习率变化下的 top-1 准确率方差更低。<sup>[9](https://research.google/blog/extending-contrastive-learning-to-the-supervised-setting/)</sup>

## 局限与替代方案

**大批次。** 损失的难负样本强化以需要大批次为代价，以包含许多正样本和负样本；<sup>[6](https://proceedings.neurips.cc/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Supplemental.pdf)</sup> 作者本人指出，在较小批次上训练是未来研究的重要课题。<sup>[9](https://research.google/blog/extending-contrastive-learning-to-the-supervised-setting/)</sup> 动量编码器记忆可以补偿：使用 8192 的记忆、批次大小 256、在 8 块 Nvidia V100 GPU 上使用 SGD，SupCon 在 ResNet-50 上达到 79.1% top-1，略优于批次 6144 且无记忆的 78.7%。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup>

**成本。** 由于多视图批次是标准批次的两倍，训练成本约为交叉熵的 2 倍，审稿人认为批次 6144 下训练 700 轮对研究界的大多数人而言不切实际。<sup>[5](https://papers.nips.cc/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Review.html)</sup>

**标签噪声。** 拟合数据所需的迭代次数随随机翻转标签比例超线性增长，不同于交叉熵的近似线性增长；在 CIFAR-10 上，监督对比损失在标签损坏超过 80% 后无法达到零误差，因为每类存活的正确实例越少，成对类内约束就越少。<sup>[8](https://proceedings.mlr.press/v139/graf21a.html)</sup>

**类坍缩与不平衡。** 当类的每个点映射到相同嵌入时损失最小化，这破坏了标签中未编码的信息（如品种、姿态或背景），损害迁移性和鲁棒性。<sup>[17](https://proceedings.mlr.press/v162/chen22d/chen22d.pdf)</sup><sup> • </sup><sup>[18](https://mdpi-res.com/d_attachment/csmf/csmf-03-00004/article_deploy/csmf-03-00004.pdf?version=1650444797)</sup> 在二类不平衡下，性能随不平衡增加而下降且表示空间坍缩，因为最终层的梯度以正样本数量的倒数为上界，多数类梯度饱和。<sup>[2](https://openaccess.thecvf.com/content/CVPR2025/papers/Mildenberger_A_Tale_of_Two_Classes_Adapting_Supervised_Contrastive_Learning_to_CVPR_2025_paper.pdf)</sup> TSC 解决了长尾数据问题，但需要预先知道类数才能计算其目标。<sup>[19](https://openaccess.thecvf.com/content/CVPR2022/papers/Li_Targeted_Supervised_Contrastive_Learning_for_Long-Tailed_Recognition_CVPR_2022_paper.pdf)</sup>

与交叉熵相比，SupCon 以两阶段协议和翻倍的训练成本换取更好的嵌入、腐蚀鲁棒性和超参数稳定性。与三元组损失相比，它消除了显式难样本挖掘；与 SimCLR 等自监督对比方法相比，它利用标签避免假阴性并为每个锚点增加多个正样本。<sup>[1](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)</sup><sup> • </sup><sup>[9](https://research.google/blog/extending-contrastive-learning-to-the-supervised-setting/)</sup>

## References

1. [Supervised Contrastive Learning (Khosla et al., NeurIPS 2020)](https://proceedings.neurips.cc/paper_files/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Paper.pdf)
2. [A Tale of Two Classes: Adapting Supervised Contrastive Learning to Binary Imbalanced Datasets (CVPR 2025)](https://openaccess.thecvf.com/content/CVPR2025/papers/Mildenberger_A_Tale_of_Two_Classes_Adapting_Supervised_Contrastive_Learning_to_CVPR_2025_paper.pdf)
3. [Khosla, Prannay and colleagues (2020). Supervised Contrastive Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2004.11362)
4. [HobbitLong/SupContrast (PyTorch reference implementation)](https://github.com/hobbitlong/supcontrast)
5. [NeurIPS 2020 official reviews for Supervised Contrastive Learning](https://papers.nips.cc/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Review.html)
6. [Supervised Contrastive Learning, Supplementary Material](https://proceedings.neurips.cc/paper/2020/file/d89a66c7c80a29b1bdbab0f2a1a94af8-Supplemental.pdf)
7. [A Simple Framework for Contrastive Learning of Visual Representations (SimCLR)](https://arxiv.org/pdf/2002.05709v3.pdf)
8. [Dissecting Supervised Contrastive Learning (Graf et al., ICML 2021)](https://proceedings.mlr.press/v139/graf21a.html)
9. [Extending Contrastive Learning to the Supervised Setting (Google Research blog)](https://research.google/blog/extending-contrastive-learning-to-the-supervised-setting/)
10. [google-research/supcon (official TensorFlow implementation)](https://github.com/google-research/google-research/tree/master/supcon)
11. [Oord, Aaron van den, Li, Yazhe, Vinyals, Oriol (2018). Representation Learning with Contrastive Predictive Coding. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1807.03748)
12. [Chen, Ting and colleagues (2020). A Simple Framework for Contrastive Learning of Visual Representations. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2002.05709)
13. [Li, Tianhong and colleagues (2021). Targeted Supervised Contrastive Learning for Long-Tailed Recognition. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2111.13998)
14. [Chen, Mayee F. and colleagues (2022). Perfectly Balanced: Improving Transfer and Robustness of Supervised Contrastive Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2204.07596)
15. [Mildenberger, David and colleagues (2025). A Tale of Two Classes: Adapting Supervised Contrastive Learning to Binary Imbalanced Datasets. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2503.17024)
16. [Similarity-Dissimilarity Loss for Multi-label Supervised Contrastive Learning](https://arxiv.org/html/2410.13439v5)
17. [Perfectly Balanced: Improving Transfer and Robustness of Supervised Contrastive Learning (ICML 2022)](https://proceedings.mlr.press/v162/chen22d/chen22d.pdf)
18. [The Details Matter: Preventing Class Collapse in Supervised Contrastive Learning](https://mdpi-res.com/d_attachment/csmf/csmf-03-00004/article_deploy/csmf-03-00004.pdf?version=1650444797)
19. [Targeted Supervised Contrastive Learning for Long-Tailed Recognition (CVPR 2022)](https://openaccess.thecvf.com/content/CVPR2022/papers/Li_Targeted_Supervised_Contrastive_Learning_for_Long-Tailed_Recognition_CVPR_2022_paper.pdf)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods › Supervised, unsupervised, and semi-supervised learning

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/supervised-contrastive-learning

English original: https://www.edgepedia.org/supervised-contrastive-learning
