# MoCo（机器学习）

**MoCo**（Momentum Contrast，动量对比）是一个用于视觉表征学习的对比式自监督学习框架，由[何恺明](https://www.edgepedia.org/zh/kaiming-he)（Kaiming He）及其同事在 CVPR 2020 论文《用于无监督视觉表征学习的动量对比》中提出。它无需标签即可训练图像编码器，方法是将对比学习视为字典查询问题：编码后的“键”所构成的字典以一个队列的形式维护，复用来自最近若干小批量（mini-batch）的键；同时，编码器的第二个副本通过指数动量而非反向传播来更新<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup>。2024 年 Springer 的一篇综述将 MoCo 描述为弥合了端到端方法与记忆库方法之间的差距，使对比目标能够在时间和 GPU 显存两方面都显著降低的计算成本下进行优化<sup>[2](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup>。

| 关键事实 | 详情 |
|---|---|
| 核心机制 | 动量更新的键编码器，\( \theta_k \leftarrow m \cdot \theta_k + (1-m) \cdot \theta_q \)，外加一个复用先前小批量编码键的队列，使字典大小与批量大小解耦<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup> |
| 队列大小（v1） | K = 65536 个键，动量 m = 0.999<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup> |
| 动量的重要性 | 线性探测准确率：m = 0 时训练失败，m = 0.9 时 55.2%，m = 0.99 时 57.8%，m = 0.999 时 59.0%，m = 0.9999 时 58.9%<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup> |
| 主要准确率 | ImageNet 上 ResNet-50 线性探测：60.6%（v1），67.5%（v2，200 轮），71.1%（v2，800 轮），73.8%（v3，800 轮）；ViT-B/16 76.5%（v3，300 轮）<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup><sup> • </sup><sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup><sup> • </sup><sup>[4](https://openaccess.thecvf.com/content/ICCV2021/papers/Chen_An_Empirical_Study_of_Training_Self-Supervised_Vision_Transformers_ICCV_2021_paper.pdf)</sup> |
| 复现成本 | 200 轮 ResNet-50 预训练在 8 块 NVIDIA V100 GPU 上以批量 256 耗时 53 小时，每块 GPU 使用 5.0 GB 显存<sup>[5](https://github.com/facebookresearch/moco/blob/89d61767/README.md)</sup><sup> • </sup><sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup> |
| 2023 年后的地位 | 在 2024 年的综述中仍是标准参照点，但该领域的前沿已转向无负样本自蒸馏与掩码图像建模（DINOv2、MAE 类方法）<sup>[2](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup><sup> • </sup><sup>[6](https://visionbook.icsgen-ai.org/part-3-deep-learning-for-vision/module-25-self-supervised-foundation-models/section-25.2.html)</sup> |

## 动机与背景

对比式自监督学习训练编码器，使图像的一个增强视图（“查询”）与同一图像的另一视图（“正键”）的匹配程度，强于其与其他图像编码（“负键”）的匹配程度。MoCo 的作者将此视为字典查询：学习信号来自将查询与一个大型键字典进行比较<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup>。

此前的两种设计各有缺陷。端到端方法用与查询相同的参数来编码键，因此键是一致的，但字典受限于当前小批量，而数千量级的有效批量需要 TPU 级别的硬件<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup><sup> • </sup><sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup>。更早的实例判别方法 InstDis（Wu 等人，2018）维护一个记忆库 \( V = \{v_j\} \)，为每个训练样本存储一个特征向量<sup>[7](https://arxiv.org/abs/1805.01978)</sup>。MoCo 用最近键的队列取代了逐样本记忆库，并且根据 2024 年的一篇综述，它是首个使用指数移动平均（EMA）更新来稳定键编码器的对比方法<sup>[8](https://arxiv.org/html/2405.04969)</sup>。由于队列丢弃旧键而非追踪每个样本，MoCo 比记忆库更节省内存，并可在十亿级数据上训练<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup>。

## 工作原理

MoCo 训练两个架构相同的编码器。参数为 \( \theta_q \) 的查询编码器 \( f_q \) 通过反向传播正常更新。参数为 \( \theta_k \) 的键编码器 \( f_k \) 从不通过梯度更新，而是遵循动量规则

\[ \theta_k \leftarrow m \cdot \theta_k + (1-m) \cdot \theta_q, \qquad m \in [0,1) \]

因此 \( \theta_k \) 缓慢地向 \( \theta_q \) 靠拢<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup>。在基于队列的 MoCo 版本中，每个小批量由 \( f_k \) 编码的键入队，最旧的键出队，因此字典始终保存最近的编码，同时远大于批量<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup><sup> • </sup><sup>[8](https://arxiv.org/html/2405.04969)</sup>。

训练目标是 InfoNCE 对比损失，它将任务视为在字典的负样本中识别正键<sup>[8](https://arxiv.org/html/2405.04969)</sup>。动量系数控制键的一致性程度。作者假设，若不加动量（m = 0）直接将 \( \theta_q \) 复制到 \( \theta_k \) 会失败，因为快速变化的编码器会降低键表征的一致性<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup>。他们的消融实验证实了这一点：m = 0 时训练直接失败，m = 0.9 给出 55.2% 的线性探测准确率，而默认的 m = 0.999 给出 59.0%，表明缓慢演化的键编码器是使用队列的核心<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup>。

## 版本：MoCo v1、v2 与 v3

**MoCo v1（CVPR 2020）** 确立了队列与动量编码器，K = 65536，m = 0.999<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup>。

**MoCo v2（2020）** 采用了 SimCLR 的两个要素：一个仅在无监督训练期间使用的 2 层 MLP 投影头（隐藏维度 2048，带 ReLU），以及包括模糊在内的更强数据增强，外加余弦学习率调度<sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup><sup> • </sup><sup>[2](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup>。增益显著：使用 MLP 头和最优温度 \( \tau = 0.2 \) 时，准确率从 60.6% 升至 66.2%；仅加模糊即提升 2.8 个点至 63.4%；两者合用达到 67.3%<sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup>。

**MoCo v3（ICCV 2021，Chen 与何恺明）** 将该框架适配到视觉 Transformer，并在此过程中舍弃了其标志性组件。论文放弃了记忆队列，发现当批量足够大（例如 4096）时其增益递减，转而使用同一批量中共存的键，配合对称化损失 \( \mathrm{ctr}(q_1, k_2) + \mathrm{ctr}(q_2, k_1) \) 和一个新增的预测头<sup>[4](https://openaccess.thecvf.com/content/ICCV2021/papers/Chen_An_Empirical_Study_of_Training_Self-Supervised_Vision_Transformers_ICCV_2021_paper.pdf)</sup>。针对 ViT，它引入了稳定性修正：冻结初始的 patch 嵌入，或使用固定的随机投影，以防止梯度尖峰，并采用 AdamW 和 40 轮预热（ResNet 则用 LARS）<sup>[8](https://arxiv.org/html/2405.04969)</sup>。最初的 v3 在 TPU 上用 [TensorFlow](https://www.edgepedia.org/zh/tensorflow) 实现；官方 PyTorch 仓库复现了论文结果<sup>[9](https://github.com/facebookresearch/moco-v3/blob/main/README.md)</sup>。

## 数据一览

ImageNet 线性探测 top-1 准确率（在冻结特征上训练线性分类器）勾勒出该系列在 ResNet-50 上的进展：v1 为 60.6%，v2 在 200 轮为 67.5%，v2 在 800 轮为 71.1%，v3 在 800 轮为 73.8%，其间还有“MoCo v2+”为 72.2%<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup><sup> • </sup><sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup><sup> • </sup><sup>[4](https://openaccess.thecvf.com/content/ICCV2021/papers/Chen_An_Empirical_Study_of_Training_Self-Supervised_Vision_Transformers_ICCV_2021_paper.pdf)</sup>。在 300 轮的 ViT 上，MoCo v3 用 ViT-S/16 达到 72.5%，用 ViT-B/16 达到 76.5%，领先于 SimCLR（69.0% 与 73.9%）、[BYOL](https://www.edgepedia.org/zh/byol)（71.0% 与 73.9%）和 SwAV（67.1% 与 71.6%）<sup>[4](https://openaccess.thecvf.com/content/ICCV2021/papers/Chen_An_Empirical_Study_of_Training_Self-Supervised_Vision_Transformers_ICCV_2021_paper.pdf)</sup>。官方 v3 仓库报告了一个在有监督微调后达到 83.2% top-1 的配置，所有结果均在批量 4096 下取得<sup>[9](https://github.com/facebookresearch/moco-v3/blob/main/README.md)</sup>。

独立复现大体证实了官方数字。官方 v1/v2 仓库报告 ResNet-50 在 200 轮下于 8 块 V100 GPU 上耗时 53 小时，分别达到 60.8 ± 0.2%（v1）和 67.5 ± 0.1%（v2），五次试验的分布为 {60.6, 60.6, 60.7, 60.9, 61.1}% 和 {67.7, 67.6, 67.4, 67.6, 67.3}%<sup>[5](https://github.com/facebookresearch/moco/blob/89d61767/README.md)</sup>。MMSelfSup 对 v3 的复现报告 ResNet-50 线性准确率在批量 4096 下为 69.6%（100 轮）、72.8%（300 轮）和 74.4%（800 轮），ViT-base 为 76.9% 线性与 83.0% 微调，ViT-large 微调为 83.7%<sup>[10](https://mmselfsup.readthedocs.io/en/latest/papers/mocov3.html)</sup>。

算力是核心卖点。在批量 256 下，MoCo v2 每块 GPU 使用 5.0 GB 显存、每 200 轮耗时 53 小时，而同样批量下端到端替代方案为 7.4 GB 和 65 小时；批量 4096 的端到端训练将需要每块 GPU 93.0 GB，论文将其标记为不可行<sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup>。MoCo v3 的 ResNet-50 配方使用 LARS、批量 4096、学习率 0.3、权重衰减 1.5e-6、温度 \( \tau = 1.0 \)、动量 m = 0.996<sup>[4](https://openaccess.thecvf.com/content/ICCV2021/papers/Chen_An_Empirical_Study_of_Training_Self-Supervised_Vision_Transformers_ICCV_2021_paper.pdf)</sup>。

## 与 SimCLR、BYOL 及后续方法的比较

SimCLR 是 MoCo 最接近的对比方法亲属，但走的是端到端路线：两个视图由同一个梯度更新的网络编码，因此字典就是批量，SimCLR 依赖 4096 至 8192 的批量及 TPU 支持。在匹配的 200 轮、批量 256 设置下，MoCo v2 达到 67.5%，高出 SimCLR 5.6 个点，甚至高于 SimCLR 在批量 8192 下的 66.6%；在 800 轮下 MoCo v2 达到 71.1%，而 SimCLR 在 1000 轮下为 69.3%<sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup>。

BYOL（2020）和 SimSiam（2021）更进一步，完全去除了负样本，表明仅凭正样本对即可学到强表征，并使用机制防止坍缩为常数输出的平凡解；MoCo 的动量编码器由此成为这个最初与其对立的无负样本家族的关键要素<sup>[6](https://visionbook.icsgen-ai.org/part-3-deep-learning-for-vision/module-25-self-supervised-foundation-models/section-25.2.html)</sup>。在 ResNet-50 上的正面交锋中，BYOL 的 74.3% 超过 MoCo v3 的 73.8%，而 MoCo v3 在两种 ViT 规模上均领先<sup>[4](https://openaccess.thecvf.com/content/ICCV2021/papers/Chen_An_Empirical_Study_of_Training_Self-Supervised_Vision_Transformers_ICCV_2021_paper.pdf)</sup>。

v2 论文的一个告诫：线性分类准确率与检测任务中的迁移性能并非单调相关；仅加模糊的变体在检测中的迁移效果优于得分更高的 MLP 变体<sup>[3](https://ar5iv.labs.arxiv.org/html/2003.04297)</sup>。

## 理解与争论

字典大小为何重要？对 InfoNCE 的双温度分解发现，损失中标量分量对字典大小高度敏感，字典小时表现差得多；而向量分量中仅 64 个键的字典已足以获得有竞争力的性能，性能在字典大小约 256 时最优，而在该设置中，这仅相当于上一次迭代产生的键<sup>[11](https://ar5iv.labs.arxiv.org/html/2203.17248)</sup>。

动量系数的最优值本身也随版本而变。对于带队列的 ResNet-50，m = 0.999 明显最佳<sup>[1](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)</sup>。对于 v3 中不带队列的 ViT-B/16，最优值为 m = 0.99（76.5%），m = 0.9 给出 75.6%，m = 0.999 给出 75.0%，m = 0 给出 74.3%；动量编码器相比完全不用动量仍贡献了 2.2 个点的增益<sup>[4](https://openaccess.thecvf.com/content/ICCV2021/papers/Chen_An_Empirical_Study_of_Training_Self-Supervised_Vision_Transformers_ICCV_2021_paper.pdf)</sup>。这两个结果并不矛盾，而是表明“通常取 0.999”的规则是队列机制所特有的，并非普适常数。

## 遗产与近期发展

MoCo 在 2023 年后的文献中仍是标准参照点：2024 年 Springer 的一篇综述在其自监督方法分类中收录了 MoCo v2 的改动，2024 年的一篇评论将 MoCo v3 描述为迈向现代视觉自监督框架的关键一步<sup>[2](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup><sup> • </sup><sup>[8](https://arxiv.org/html/2405.04969)</sup>。然而研究前沿已经向前推进。截至 2024 至 2026 年，以 DINOv2 为代表的主流自监督骨干网络将无负样本自蒸馏与掩码建模相结合，而非经典对比学习<sup>[6](https://visionbook.icsgen-ai.org/part-3-deep-learning-for-vision/module-25-self-supervised-foundation-models/section-25.2.html)</sup>。ICLR 2025 上结合掩码码本预测与自监督学习的工作报告了最先进的低样本结果，训练速度至少比先前方法快 3 倍，其衡量基准正是 MoCo 帮助建立的对比学习时代的基线<sup>[12](https://iclr.cc/virtual/2025/poster/31503)</sup>。

## References

1. [Kaiming He, Haoqi Fan, Yuxin Wu, Saining Xie, Ross Girshick (2020). Momentum Contrast for Unsupervised Visual Representation Learning. CVPR 2020.](https://openaccess.thecvf.com/content_CVPR_2020/papers/He_Momentum_Contrast_for_Unsupervised_Visual_Representation_Learning_CVPR_2020_paper.pdf)
2. [A survey on self-supervised methods for visual representation learning. Machine Learning (Springer, 2024).](https://link.springer.com/article/10.1007/s10994-024-06708-7)
3. [Xinlei Chen, Haoqi Fan, Ross Girshick, Kaiming He (2020). Improved Baselines with Momentum Contrastive Learning (MoCo v2). arXiv:2003.04297.](https://ar5iv.labs.arxiv.org/html/2003.04297)
4. [Xinlei Chen, Kaiming He (2021). An Empirical Study of Training Self-Supervised Vision Transformers (MoCo v3). ICCV 2021.](https://openaccess.thecvf.com/content/ICCV2021/papers/Chen_An_Empirical_Study_of_Training_Self-Supervised_Vision_Transformers_ICCV_2021_paper.pdf)
5. [facebookresearch/moco README (official v1/v2 reproduction results).](https://github.com/facebookresearch/moco/blob/89d61767/README.md)
6. [Section 25.2: Contrastive Learning: SimCLR & MoCo, Building Vision AI.](https://visionbook.icsgen-ai.org/part-3-deep-learning-for-vision/module-25-self-supervised-foundation-models/section-25.2.html)
7. [Zhirong Wu et al. (2018). Unsupervised Feature Learning via Non-Parametric Instance Discrimination. arXiv:1805.01978.](https://arxiv.org/abs/1805.01978)
8. [A Review on Discriminative Self-supervised Learning Methods in Computer Vision (2024). arXiv:2405.04969.](https://arxiv.org/html/2405.04969)
9. [facebookresearch/moco-v3 README (official repository).](https://github.com/facebookresearch/moco-v3/blob/main/README.md)
10. [MoCo v3, MMSelfSup documentation (independent reproduction).](https://mmselfsup.readthedocs.io/en/latest/papers/mocov3.html)
11. [Dual Temperature Helps Contrastive Learning Without Many Negative Samples: Towards Understanding and Simplifying MoCo. arXiv:2203.17248.](https://ar5iv.labs.arxiv.org/html/2203.17248)
12. [MOCA: Self-supervised Representation Learning by Predicting Masked Online Codebook Assignments. ICLR 2025.](https://iclr.cc/virtual/2025/poster/31503)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Neural networks and deep learning › Generative and self-supervised models

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/moco-machine-learning

English original: https://www.edgepedia.org/moco-machine-learning
