# SimCLR

SimCLR（A Simple Framework for Contrastive Learning of Visual Representations，视觉表征对比学习简易框架）是一种自监督学习方法，通过最大化同一图像两个不同增强视图之间的一致性，同时推开不同图像的表征，来训练图像编码器。训练完成后，编码器产生的表征可迁移至下游任务，而预训练过程中无需使用任何标签。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> 据报道，它是早期自监督方法（如Exemplar-CNN、Instance Discrimination、CPC、AMDIM、CMC和MoCo）的更简洁的替代方案，后者需要对架构或训练流程做较大改动。<sup>[2](https://research.google/blog/advancing-self-supervised-and-semi-supervised-learning-with-simclr/)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 一个编码器 \( f(\cdot) \)，其表征 \( h \) 用于下游任务；投影头 \( g(\cdot) \) 在训练后被丢弃<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> |
| 损失 | NT-Xent，即归一化温度缩放交叉熵损失，作用于增强视图对<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> |
| 默认配置 | ResNet-50编码器，2层MLP投影至128维，LARS优化器，批大小4096，100个epoch<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> |
| 标志性结果 | ResNet-50（4×）在ImageNet上线性探测top-1准确率76.5%，与有监督ResNet-50持平<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> |
| 计算量 | ResNet-50、批大小4096、100个epoch，在128个TPU v3核心上约1.5小时<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> |
| 主要变体 | SimCLRv2（半监督预训练–微调–蒸馏）和SimCSE（句嵌入）<sup>[3](https://proceedings.neurips.cc/paper/2020/file/fcbc95ccdd551da181207c0c1400c655-Paper.pdf)</sup><sup> • </sup><sup>[4](https://doi.org/10.48550/arxiv.2104.08821)</sup> |

## 工作原理

SimCLR通过对同一图像施加两个独立的随机增强序列——随机裁剪并缩放回原始尺寸、随机颜色失真和随机高斯模糊——来构建正样本对。基础编码器 \( f(\cdot) \)（一个ResNet）将每个视图映射为表征 \( h \)，投影头 \( g(\cdot) \)（一个含一个隐藏ReLU层的MLP）将 \( h \) 映射为潜在向量 \( z \)，损失在 \( z \) 上计算。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup>

损失为NT-Xent，即归一化温度缩放交叉熵损失。对于正样本对 \( (i, j) \)，余弦相似度记为 \( \mathrm{sim}(\cdot, \cdot) \)，温度为 \( \tau \)：

\[ \ell_{i,j} = -\log \frac{\exp(\mathrm{sim}(z_i, z_j)/\tau)}{\sum_{k=1}^{2N} \mathbb{1}_{[k \neq i]} \exp(\mathrm{sim}(z_i, z_k)/\tau)} \]

最终损失对小批量中所有正样本对 \( (i,j) \) 和 \( (j,i) \) 求和。负样本不显式采样：小批量中其余 \( 2(N-1) \) 个增强样本充当负样本，因此一批8192张图像为每个正样本对提供16382个负样本。不使用记忆库。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> 投影头之所以重要，是因为从中取出的表征针对不变性进行了调优，在下游任务上表现不如编码器的 \( h \) 输出；训练后丢弃 \( g(\cdot) \) 可恢复迁移性更好的特征。<sup>[5](https://lightning.ai/docs/pytorch/LTS/notebooks/course_UvA-DL/13-contrastive-learning.html)</sup>

## 实现方法

实践者运行以下流程：

1. **增强**：对每张图像施加两次随机裁剪与缩放、颜色失真和[高斯模糊](https://www.edgepedia.org/zh/gaussian-blur)。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup>
2. **编码**：用ResNet对两个视图编码，再用2层MLP（一个隐藏ReLU层）投影至128维空间。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup>
3. **优化**：用LARS优化器优化NT-Xent，该优化器根据梯度范数缩放学习率以稳定大批量训练，采用线性学习率缩放 \( \mathrm{LearningRate} = 0.3 \times \mathrm{BatchSize}/256 \) 和权重衰减 \( 10^{-6} \)。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup><sup> • </sup><sup>[6](https://icml.cc/media/icml-2020/Slides/6762.pdf)</sup>
4. **训练**：批大小4096，训练100个epoch，前10个epoch线性预热后余弦衰减。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup>
5. **评估**：丢弃投影头，在冻结的编码器表征上训练线性分类器（线性探测），或在有标签数据上微调编码器。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup>

原始结果在批大小4096下调优，较小批大小时结果欠佳；官方代码库指出，重新调优超参数（主要是学习率、温度和投影头深度）后，小批量可达到大批量结果。<sup>[7](https://github.com/google-research/simclr/blob/master/README.md)</sup>

## 起源

SimCLR由陈霆（Ting Chen）及其同事于2020年在arXiv上发表的《视觉表征对比学习简易框架》中提出。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> 相对于先前的对比方法，该论文的贡献在于三项发现的组合：增强的组合（尤其是裁剪配合颜色失真）至关重要；损失前的投影头提升表征质量；对比学习比有监督学习更受益于更大批量和更长训练。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> 它建立在论文明确致谢的早期工作之上：损失项此前已被Sohn 2016、Wu等2018和Oord等2018使用，ResNet编码器来自He等2016，LARS优化器来自You等2017。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup>

## 变体

**SimCLRv2**由陈霆及其同事于2020年在arXiv上发表的《大型自监督模型是强大的半监督学习器》中提出。<sup>[8](https://doi.org/10.48550/arxiv.2006.10029)</sup> 它是一个三步半监督框架：自监督预训练、有监督微调，以及利用无标签数据的蒸馏；两张增强图像由ResNet \( f(\cdot) \) 编码，再经非线性网络 \( g(\cdot) \) 变换。<sup>[3](https://proceedings.neurips.cc/paper/2020/file/fcbc95ccdd551da181207c0c1400c655-Paper.pdf)</sup> SimCLRv2仅使用1%的有标签图像，在[ImageNet](https://www.edgepedia.org/zh/imagenet)上达到85.8%的top-5准确率，创下有限标签分类的纪录。<sup>[3](https://proceedings.neurips.cc/paper/2020/file/fcbc95ccdd551da181207c0c1400c655-Paper.pdf)</sup>

**SimCSE**将同样的对比方法应用于句嵌入；由高天宇（Tianyu Gao）、姚星丞（Xingcheng Yao）和陈丹琦（Danqi Chen）于2021年在arXiv上提出。<sup>[4](https://doi.org/10.48550/arxiv.2104.08821)</sup> 其无监督和有监督模型在STS任务上以BERT-base达到平均Spearman相关系数76.3%和81.6%，比此前最佳结果分别提升4.2%和2.2%。<sup>[4](https://doi.org/10.48550/arxiv.2104.08821)</sup>

## 应用

在ImageNet线性探测上，SimCLR配合ResNet-50达到69.3% top-1 / 89.0% top-5，ResNet-50（2×）达到74.2% / 92.0%，ResNet-50（4×）达到76.5% / 93.2%。76.5%的top-1结果相对此前最佳水平提升7%，与有监督ResNet-50持平。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup><sup> • </sup><sup>[2](https://research.google/blog/advancing-self-supervised-and-semi-supervised-learning-with-simclr/)</sup> 在1%标签上微调后，SimCLR达到85.8% top-5准确率，以百分之一的标签数超越AlexNet。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup>

缩放行为与有监督学习不同。有监督ResNet在ImageNet上的性能在90至300个训练epoch之间达到峰值，但SimCLR即使800个epoch后仍持续提升，网络深度或宽度增加时增益也持续。<sup>[2](https://research.google/blog/advancing-self-supervised-and-semi-supervised-learning-with-simclr/)</sup> 更大批量提供更多负样本并加速收敛，不过批量之间的差距随训练时间延长而缩小。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup>

在医学影像方面，SimCLR预训练被应用于皮肤科和CheXpert胸部X光分类，并有多实例对比学习（MICLe）扩展，从同一病症的多张图像构建额外正样本对；自监督预训练优于有监督ImageNet预训练，包括1400万图像的有监督预训练。<sup>[9](https://ar5iv.labs.arxiv.org/html/2101.05224)</sup>

增强选择充当隐式监督：它们定义了模型可以视为无关的特征。单一变换不够；随机裁剪与随机颜色失真的组合至关重要，因为仅凭颜色直方图就能以捷径方式解决对比任务，因此裁剪必须与颜色失真组合才能学到可泛化的特征。<sup>[1](https://doi.org/10.48550/arxiv.2002.05709)</sup> 领[域适应](https://www.edgepedia.org/zh/domain-adaptation)遵循同样的逻辑。对于CheXpert胸部X光，最佳增强为随机裁剪、强度0.5的颜色抖动、最多45度旋转和水平翻转，而高斯模糊被舍弃，因为它可能遮蔽与疾病判读相关的局部纹理变化。<sup>[9](https://ar5iv.labs.arxiv.org/html/2101.05224)</sup>

## 局限与替代方案

SimCLR的主要实际约束是对大批量的依赖，因为负样本仅来自当前小批量。[BYOL](https://www.edgepedia.org/zh/byol)等方法避免了SimCLR所需的大批量，在计算资源有限时更为有利。<sup>[10](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup> MoCo则维护一个大型样本记忆库来计算对比损失，而SimCLR不使用记忆库；DIM最大化编码器输入与输出区域之间的互信息。<sup>[11](https://arxiv.org/pdf/2103.14005v2.pdf)</sup>

自2023年末以来，对比范式与更新的方法并行发展。SynCLR是2023年末的后继方法，从合成图像进行对比训练，在ImageNet-1K上达到80.7%（ViT-B）和83.0%（ViT-L）的top-1线性探测准确率，与OpenAI的CLIP相当。<sup>[12](https://arxiv.org/abs/2312.17742)</sup> 掩码图像建模和结合对比与自蒸馏思想的DINO v2，与对比学习并列为领域无关的自监督方法。<sup>[12](https://arxiv.org/abs/2312.17742)</sup> 自监督对比学习在2025年仍是活跃的研究课题，一篇NeurIPS论文将其描述为视觉和NLP领域最成功的无监督学习范式之一。<sup>[13](https://proceedings.neurips.cc/paper_files/paper/2025/file/3b85cbbaab0008dfc52250a857725f70-Paper-Conference.pdf)</sup>

## References

1. [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)
2. [Advancing Self-Supervised and Semi-Supervised Learning with SimCLR](https://research.google/blog/advancing-self-supervised-and-semi-supervised-learning-with-simclr/)
3. [Big Self-Supervised Models are Strong Semi-Supervised Learners (SimCLRv2)](https://proceedings.neurips.cc/paper/2020/file/fcbc95ccdd551da181207c0c1400c655-Paper.pdf)
4. [Gao, Tianyu, Yao, Xingcheng, Chen, Danqi (2021). SimCSE: Simple Contrastive Learning of Sentence Embeddings. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2104.08821)
5. [Tutorial 13: Self-Supervised Contrastive Learning with SimCLR, PyTorch Lightning documentation](https://lightning.ai/docs/pytorch/LTS/notebooks/course_UvA-DL/13-contrastive-learning.html)
6. [SimCLR ICML 2020 slides](https://icml.cc/media/icml-2020/Slides/6762.pdf)
7. [google-research/simclr README](https://github.com/google-research/simclr/blob/master/README.md)
8. [Chen, Ting and colleagues (2020). Big Self-Supervised Models are Strong Semi-Supervised Learners. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2006.10029)
9. [Big Self-Supervised Models Advance Medical Image Classifications](https://ar5iv.labs.arxiv.org/html/2101.05224)
10. [A survey on self-supervised methods for visual representation learning](https://link.springer.com/article/10.1007/s10994-024-06708-7)
11. [Contrasting Contrastive Self-Supervised Representation Learning Pipelines](https://arxiv.org/pdf/2103.14005v2.pdf)
12. [Learning Vision from Models Rivals Learning Vision from Data (SynCLR)](https://arxiv.org/abs/2312.17742)
13. [Self-Supervised Contrastive Learning is Approximately Supervised Contrastive Learning](https://proceedings.neurips.cc/paper_files/paper/2025/file/3b85cbbaab0008dfc52250a857725f70-Paper-Conference.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 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/simclr

English original: https://www.edgepedia.org/simclr
