# 前置任务

前置任务是人工构造出来的训练任务，机器学习模型求解它并非为了任务本身，而是为了迫使模型学到能够迁移到真实下游任务上的表征；这一术语也被译作代理任务或替代任务。<sup>[1](https://arxiv.org/html/2301.05712v2)</sup> 它是计算机视觉中自监督学习的核心机制：标签由数据自身的属性自动生成，因此训练无需人工标注。<sup>[2](https://link.springer.com/article/10.1007/s10462-026-11506-9)</sup> 该流程产出的是一个训练好的编码器网络；任务专用的输出层被丢弃，编码器的权重或表征被复用于分类、检测或分割。<sup>[3](https://ar5iv.labs.arxiv.org/html/2308.11455)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 仅为获得一个有前景的预训练模型而求解的任务，其解本身并不令人感兴趣；亦称代理任务或替代任务<sup>[1](https://arxiv.org/html/2301.05712v2)</sup> |
| 保留什么 | 训练结束后，投影网络、预测网络与分类头均被丢弃，下游只使用编码器 \( f_{\theta} \)<sup>[3](https://ar5iv.labs.arxiv.org/html/2308.11455)</sup> |
| 相对图块位置 | 预测两个图块之间 8 种相对空间关系中的一种（如“下方”或“右上方”）<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup> |
| 旋转预测 | 对旋转 \( \{0^{\circ}, 90^{\circ}, 180^{\circ}, 270^{\circ}\} \) 做 4 分类<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup> |
| 拼图排列 | 原始设计中，\( 3 \times 3 \) 网格从 \( 9! = 362\,880 \) 种排列里预定义 1000 种；一个被广泛使用的复现实现则使用固定的 100 种<sup>[5](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup><sup> • </sup><sup>[3](https://ar5iv.labs.arxiv.org/html/2308.11455)</sup><sup> • </sup><sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup> |
| ImageNet 线性评估 | 上下文预测 51.4% top-1；最强的旋转模型 55.4% top-1，数据出自科列斯尼科夫等（CVPR 2019）的基准<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup> |
| 范式 | 自监督学习分为预测式、对比式与生成式三类，均建立在前置任务这一构想之上<sup>[2](https://link.springer.com/article/10.1007/s10462-026-11506-9)</sup> |

## 原理

早期的自监督方法构造伪标签——即由数据集属性自动生成的标签——并训练网络去预测它们。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC9029566/)</sup> 最早的一批此类任务大多是预测式的：监督信号来自数据自身的几何变换，例如预测两个图块的相对位置、预测施加于图像的旋转，或预测打乱图块所用的排列。<sup>[2](https://link.springer.com/article/10.1007/s10462-026-11506-9)</sup>

设计的关键在于对齐。前置任务的设计大多是手工完成的，需要关于数据结构的领域知识或专家知识，而且任务所诱导的不变性应与下游任务相匹配：对空间朝向的不变性有助于分类，但对目标定位却适得其反。<sup>[2](https://link.springer.com/article/10.1007/s10462-026-11506-9)</sup>

## 做法

标准流程分三个阶段。第一，在无标注图像集合上就前置任务预训练网络。第二，丢弃任务专用的头：在旋转预测中，训练完成后分类头 \( q_{\psi} \) 被移除，只使用主干 \( f_{\theta} \)，用它计算未旋转图像的表征。<sup>[5](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup> 第三，以下游任务评估，方式有二：微调把前置任务的权重当作初始化，并更新全部权重；线性分类器则冻结预训练权重，只用带标注的数据训练一个小型的头。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC9029566/)</sup> 下游任务仍然需要带标注的数据集，但要取得良好表现，只需一个小数据集。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC9029566/)</sup>

架构选择依目标领域而定：旋转预测那项工作在 CIFAR-10 上的实验使用 Network-in-Network，在 ImageNet 上的实验使用 AlexNet。<sup>[5](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup>

## 起源

多尔施、古普塔与埃弗罗斯的上下文预测论文《通过上下文预测进行无监督视觉表征学习》（"Unsupervised Visual Representation Learning by Context Prediction"）于 2015 年出现在 arXiv 上；该文训练一个卷积网络来分类两个图像图块的相对位置。<sup>[7](https://doi.org/10.48550/arxiv.1505.05192)</sup><sup> • </sup><sup>[8](https://arxiv.org/pdf/1603.09246)</sup> 后来的一项基准研究把上下文预测描述为这一研究方向中最早发表的方法之一，正因如此，这篇 2015 年的论文被视为预测式前置任务的起点。<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup> 同样发表于 arXiv 的《通过求解拼图游戏无监督学习视觉表征》（"Unsupervised Learning of Visual Representations by Solving Jigsaw Puzzles"）一文，则把这一想法从两个图块扩展到一个被打乱的图块网格。<sup>[8](https://arxiv.org/pdf/1603.09246)</sup><sup> • </sup><sup>[5](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup>

## 变体

**相对图块位置。** 从图像中取出两个图块，由网络预测它们的相对位置，即“下方”“右上方”等 8 类之一。<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup> 为阻断低层次的捷径，两个图块之间留出约半个图块宽度的间隙，且每个图块的位置随机抖动至多 7 像素。<sup>[7](https://doi.org/10.48550/arxiv.1505.05192)</sup>

**拼图游戏。** 图像被切成 \( 3 \times 3 \) 的网格并打乱；模型预测所用的是 1000 种预定义排列中的哪一种，而可能的排列共有 \( 9! = 362\,880 \) 种。<sup>[5](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup><sup> • </sup><sup>[3](https://ar5iv.labs.arxiv.org/html/2308.11455)</sup> 科列斯尼科夫等人的实现则使用固定的 100 种排列；这两个数字反映的是不同实现，而非某个定论性的单一取值。<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup> 防捷径的措施包括：以随机间隙采样图块；以 2/3 的概率将每个图块独立地转为灰度；把图块归一化为零均值、单位标准差——以此击败色差、边缘对齐之类的线索。<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup>

**旋转预测。** 单个网络看到一张被旋转 \( 0^{\circ} \)、\( 90^{\circ} \)、\( 180^{\circ} \) 或 \( 270^{\circ} \) 的图像，预测施加的是哪一种旋转，这是一个 4 分类问题；四种旋转给出最佳结果，且该增广可用翻转与转置实现，因而无需插值。<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup><sup> • </sup><sup>[3](https://ar5iv.labs.arxiv.org/html/2308.11455)</sup>

**图像修复。** 《上下文编码器》（Context Encoders）一文训练一个卷积网络，以周围环境为条件生成任意图像区域的内容，其驱动方式是基于上下文的像素预测。<sup>[9](https://ar5iv.labs.arxiv.org/html/1604.07379)</sup> 该文将单用逐像素重建损失与重建损失加对抗损失作了比较；后者产生的结果锐利得多，因为它能更好地处理输出中的多模态。<sup>[9](https://ar5iv.labs.arxiv.org/html/1604.07379)</sup>

**着色。** 为灰度图像着色被列为标准辅助前置任务之一，与旋转预测、填补图像缺失部分、相对图块位置并列。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC9029566/)</sup>

**与现代自监督的关系。** 自 2020 年以来，SimCLR、BYOL、MoCo 等对比式方法取得了可观进展；对比学习需要负样本，这抬高了计算成本，也促成了无负样本方法的出现；而在 2021 年 ViT 与掩码图像建模结合之前，对比式自监督一直压过生成式方法。<sup>[2](https://link.springer.com/article/10.1007/s10462-026-11506-9)</sup> 这些方法仍落在前置任务的框架之内：无论学习范式是预测式、对比式还是生成式，所有自监督方法都共享同一构想——用一个前置任务提取对下游任务有语义意义的视觉信息。<sup>[2](https://link.springer.com/article/10.1007/s10462-026-11506-9)</sup>

## 应用

前置任务所学特征的标准基准是 ImageNet、VOC07 与 Places205。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC9029566/)</sup> 在科列斯尼科夫等人的比较中，上下文预测在 ImageNet 线性评估上达到 51.4% 的 top-1 准确率，他们最强的旋转模型达到 55.4%；这些数字界定了经典预测式任务在线性探针评估下的水平。<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup> 上下文编码器的特征通过将编码器微调用于分类、目标检测与语义分割而得到验证，并被定量证明对这些任务上的 CNN 预训练有效。<sup>[9](https://ar5iv.labs.arxiv.org/html/1604.07379)</sup>

## 局限与替代方案

**捷径学习。** 前置任务容许平凡解。在上下文预测中，色差——一种光学效应，通常表现为绿色通道相对其他通道向图像中心收缩——使网络能够相对于相机镜头来定位图块，而非学习场景结构。<sup>[7](https://doi.org/10.48550/arxiv.1505.05192)</sup> 在拼图求解中，诺鲁齐与法瓦罗表明该方法可以走捷径，用边缘统计量作为替代，而不去学习相关的图像特征。<sup>[5](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup> 掩码图像前置模型面临一种相关的失败：若不设防，模型可能靠邻近像素预测图像图块来“作弊”，因为自然图像在空间上是冗余的，所以掩码比例必须很高。<sup>[5](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup>

**目标失配。** 一种方法可能过拟合于前置任务，从而无法泛化到图像分类等下游任务。<sup>[5](https://link.springer.com/article/10.1007/s10994-024-06708-7)</sup> 表现优异的前置任务并不保证良好的下游表现，原因在于对前置目标的过拟合以及一种饱和现象，而且前置任务与下游任务之间的关系随数据集而变。<sup>[2](https://link.springer.com/article/10.1007/s10462-026-11506-9)</sup>

**与替代方案的比较。** 在图像分类上，对比学习方法优于辅助前置技术；在一项 ImageNet 比较中，模型无标签预训练、以监督线性分类评估，SwAV 比 MoCo v2 高出 4.2%，并把与监督训练的差距缩小到 1% 以内。<sup>[6](https://pmc.ncbi.nlm.nih.gov/articles/PMC9029566/)</sup> 总体而言，预测式前置任务已被对比式与生成式方法大幅超越，但在关注感兴趣目标至关重要的细分场景中仍占一席之地，例如医学影像。<sup>[2](https://link.springer.com/article/10.1007/s10462-026-11506-9)</sup> 已发表的直接迁移性能对比确实存在，例如上下文预测论文报告了无监督预训练对比 ImageNet 标签监督预训练在 [PASCAL VOC](https://www.edgepedia.org/zh/pascal-voc) 2007 目标检测上的结果，张等人则报告了着色训练所得表征在 ImageNet 分类上的线性分类器评估。<sup>[4](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)</sup><sup> • </sup><sup>[10](https://arxiv.org/abs/1901.09005)</sup><sup> • </sup><sup>[11](https://richzhang.github.io/colorization/resources/colorful_eccv2016.pdf)</sup><sup> • </sup><sup>[12](https://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Doersch_Unsupervised_Visual_Representation_ICCV_2015_paper.pdf)</sup>

## References

1. [A Survey of Self-supervised Learning from Multiple Perspectives: Algorithms, Applications and Future Trends (arXiv 2301.05712)](https://arxiv.org/html/2301.05712v2)
2. [A survey on design choices for self-supervised learning in computer vision (Artificial Intelligence Review)](https://link.springer.com/article/10.1007/s10462-026-11506-9)
3. [A Survey on Self-Supervised Representation Learning (arXiv 2308.11455)](https://ar5iv.labs.arxiv.org/html/2308.11455)
4. [Revisiting Self-Supervised Visual Representation Learning (Kolesnikov et al., CVPR 2019)](https://openaccess.thecvf.com/content_CVPR_2019/papers/Kolesnikov_Revisiting_Self-Supervised_Visual_Representation_Learning_CVPR_2019_paper.pdf)
5. [A survey on self-supervised methods for visual representation learning (Machine Learning, 2024)](https://link.springer.com/article/10.1007/s10994-024-06708-7)
6. [Survey on Self-Supervised Learning: Auxiliary Pretext Tasks and Contrastive Learning Methods in Imaging (Entropy, 2022; PMC copy)](https://pmc.ncbi.nlm.nih.gov/articles/PMC9029566/)
7. [Doersch, Carl, Gupta, Abhinav, Efros, Alexei A. (2015). Unsupervised Visual Representation Learning by Context Prediction. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1505.05192)
8. [Unsupervised Learning of Visual Representations by Solving Jigsaw Puzzles (Noroozi & Favaro)](https://arxiv.org/pdf/1603.09246)
9. [Context Encoders: Feature Learning by Inpainting (Pathak et al., CVPR 2016)](https://ar5iv.labs.arxiv.org/html/1604.07379)
10. [arxiv.org](https://arxiv.org/abs/1901.09005)
11. [richzhang.github.io](https://richzhang.github.io/colorization/resources/colorful_eccv2016.pdf)
12. [Doersch Unsupervised Visual Representation ICCV 2015 Paper.pdf, cv-foundation.org](https://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Doersch_Unsupervised_Visual_Representation_ICCV_2015_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/pretext-task

English original: https://www.edgepedia.org/pretext-task
