# 对抗机器学习

对抗机器学习训练模型以抵御对抗输入或与竞争网络对抗，目的要么是使模型对最坏情况下的扰动具有鲁棒性，要么是生成数据。它涉及对机器学习系统的攻击及其防御；其核心防御手段是[对抗训练](https://www.edgepedia.org/zh/adversarial-training)，即将攻击样本注入训练损失中，从而产生鲁棒的分类器。生成对抗网络（GAN）让生成器与判别器相互对抗，将对抗优化应用于生成建模，与此相关，但它是一条独立的研究路线，而非该领域的主线。

起点是塞格迪（Szegedy）及其同事在2013年的观察：通过优化输入所能找到的不可感知的、非随机的扰动，可以任意改变深度网络的预测。<sup>[1](https://arxiv.org/pdf/1312.6199)</sup>随后，古德费洛（Goodfellow）、施伦斯（Shlens）和塞格迪将其转化为一种实用的训练方法，<sup>[2](https://arxiv.org/abs/1412.6572)</sup>古德费洛及其同事将GAN构建为极小极大博弈，<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2014/file/f033ed80deb0234979a61f95710dbe25-Paper.pdf)</sup>马德里（Madry）及其同事则将鲁棒训练重新表述为鞍点优化。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup>

| 关键事实 | 数值 |
|---|---|
| 核心表述 | 鞍点（极小极大）问题：外层对参数做最小化，内层对扰动做最大化<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup> |
| 标准攻击预算 | CIFAR-10上\( \epsilon = 8/255 \)，MNIST上\( \epsilon = 0.3 \)（\( \ell_{\infty} \)）<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup> |
| 该预算下的鲁棒性 | MNIST超过89%，CIFAR-10为46%（马德里等人的模型）；RobustBench上CIFAR-10在\( \ell_{\infty} = 8/255 \)下的最佳鲁棒准确率为73.71%（巴托尔德森等人，ICML 2024）<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup><sup> • </sup><sup>[5](https://www.proceedings.com/content/068/068431-0678open.pdf)</sup> |
| 干净准确率代价 | 在一项对比中，CIFAR-10的标准准确率从95.2%降至87.3%；ImageNet干净准确率损失约0.8%<sup>[6](https://par.nsf.gov/servlets/purl/10113528)</sup><sup> • </sup><sup>[7](https://research.google/pubs/adversarial-machine-learning-at-scale/)</sup> |
| 计算代价 | 对于K步PGD，约为自然训练的\( K+1 \)倍；在CIFAR-10上为10小时对20分钟<sup>[8](https://proceedings.neurips.cc/paper/2019/file/7503cfacd12053d309b6bed5c89de212-Paper.pdf)</sup><sup> • </sup><sup>[5](https://www.proceedings.com/content/068/068431-0678open.pdf)</sup> |
| GAN目标 | \( \min_G \max_D V(D,G) \)，当生成器匹配数据分布时全局最小值为\( -\log 4 \)<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2014/file/f033ed80deb0234979a61f95710dbe25-Paper.pdf)</sup> |

## 工作原理

对抗训练求解一个极小极大问题：内层最大化通过在允许的扰动集上最大化分类损失来生成对抗样本，外层最小化则更新模型参数以最小化这些样本上的损失。<sup>[9](https://proceedings.mlr.press/v97/wang19i.html)</sup>马德里及其同事将其形式化为鞍点鲁棒优化问题，并针对由投影梯度下降（PGD）计算的“一阶对手”进行训练，其更新为\( x_{t+1} = \Pi_{x+S}\left(x_t + \alpha \cdot \mathrm{sgn}(\nabla_x L(\theta, x, y))\right) \)，即在每一步之后投影回允许的球内。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup>由于在内层最大化点处取得的梯度是外层问题的有效下降方向（Danskin定理），在对抗样本损失上做SGD能一致地降低鞍点目标。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup><sup> • </sup><sup>[10](https://adversarial-ml-tutorial.org/adversarial_ml_slides_parts_2_3.pdf)</sup>

最廉价的内层最大化器是[快速梯度符号法](https://www.edgepedia.org/zh/fast-gradient-sign-method)（FGSM），它沿输入梯度的符号方向取大小为\( \epsilon \)的单步，\( \eta = \epsilon \cdot \mathrm{sign}(\nabla_x J(\theta, x, y)) \)；古德费洛、施伦斯和塞格迪认为网络的脆弱性主要源于其线性本质，这正是这种单步攻击有效的原因，并在混合目标\( \tilde{J} = \alpha J(\theta, x, y) + (1-\alpha) J(\theta, x + \eta) \)上训练，取\( \alpha = 0.5 \)。<sup>[2](https://arxiv.org/abs/1412.6572)</sup> PGD是FGSM的多步版本，通常以更高代价找到更好的内层最优解。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup><sup> • </sup><sup>[10](https://adversarial-ml-tutorial.org/adversarial_ml_slides_parts_2_3.pdf)</sup>

GAN将相同的对抗结构用于生成而非鲁棒性。其目标为\( \min_G \max_D V(D,G) = \mathbb{E}_{x \sim p_{\mathrm{data}}}[\log D(x)] + \mathbb{E}_{z \sim p_z}[\log(1 - D(G(z)))] \)；在相关准则下其全局最小值为\( -\log 4 \)，恰在生成器分布等于数据分布时达到。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2014/file/f033ed80deb0234979a61f95710dbe25-Paper.pdf)</sup>

## 具体做法

在CIFAR-10上运行PGD对抗训练的实践者，按照马德里及其同事的方案，针对PGD对手训练，步长为2共7步，在0-255像素尺度上总\( \epsilon = 8 \)，评估时最难对手使用20步；MNIST使用\( \epsilon = 0.3 \)。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup>两个设计选择最为关键：训练一个容量足够高的网络，以及使用尽可能强的对手，实现为在扰动球内随机起始的PGD。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup>随机起始正是PGD区别于基本迭代法之处，并提高了找到对抗样本的效率。<sup>[11](https://www.mdpi.com/1999-4893/15/8/283)</sup>

在ImageNet规模上，库拉金（Kurakin）、古德费洛和本吉奥（Bengio）推荐使用批归一化，批中混合正常样本和对抗样本。<sup>[7](https://research.google/pubs/adversarial-machine-learning-at-scale/)</sup>内层最大化的收敛质量本身就是一个调度问题：更好的鲁棒性需要在训练后期使用收敛质量更好的对抗样本，而早期使用高质量样本反而可能有害，因此逐步增加攻击强度的动态策略能改善鲁棒性。<sup>[9](https://proceedings.mlr.press/v97/wang19i.html)</sup> GAN训练则交替进行\( k \)步判别器更新和一步生成器更新，通常\( k = 1 \)，且在训练早期，生成器被训练为最大化\( \log D(G(z)) \)而非最小化\( \log(1 - D(G(z))) \)，以获得更强的梯度。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2014/file/f033ed80deb0234979a61f95710dbe25-Paper.pdf)</sup>

## 起源

这个问题比深度学习更古老。NIST记录的早期逃逸攻击可追溯到1988年卡恩斯（Kearns）和李（Li）的工作，以及2004年针对垃圾邮件过滤器中[线性分类器](https://www.edgepedia.org/zh/linear-classifier)的对抗样本演示；早期针对[在线机器学习](https://www.edgepedia.org/zh/online-machine-learning)的攻击分类法被提出，逃逸挑战被引入。<sup>[12](https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-2e2023.pdf?6c620d40_page=1)</sup><sup> • </sup><sup>[13](https://dl.acm.org/doi/10.1145/2046684.2046692)</sup>“对抗学习”一词被用于对抗分类器逆向工程。<sup>[14](https://arxiv.org/pdf/1810.07339)</sup>

深度学习时代始于2013年，塞格迪及其同事创造了“对抗样本”一词，通过最小化扰动的\( \ell_2 \)范数以L-BFGS求解其目标，并提出在此类样本上训练作为正则化手段。<sup>[1](https://arxiv.org/pdf/1312.6199)</sup><sup> • </sup><sup>[12](https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-2e2023.pdf?6c620d40_page=1)</sup>在2014年的一篇arXiv论文中，古德费洛、施伦斯和塞格迪提出了FGSM及基于它的对抗训练，将maxout网络在MNIST上的错误率从0.94%降至0.84%，其在FGSM样本上的错误率从89.4%降至17.9%。<sup>[2](https://arxiv.org/abs/1412.6572)</sup>库拉金、古德费洛和本吉奥用[Inception](https://www.edgepedia.org/zh/inception) v3将该方法扩展到ImageNet，工作发表于ICLR 2017。<sup>[7](https://research.google/pubs/adversarial-machine-learning-at-scale/)</sup>马德里及其同事2017年的arXiv论文提供了鞍点表述和PGD训练，成为该领域的基线。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup> GAN由古德费洛及其同事于2014年在NeurIPS上提出；该论文明确将GAN与对抗样本区分开来，后者并非训练生成模型的机制。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2014/file/f033ed80deb0234979a61f95710dbe25-Paper.pdf)</sup>

## 变体

**PGD对抗训练**是基线：多步PGD作为内层最大化器，随机起始，高容量网络。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup> **TRADES**将鲁棒误差分解为自然误差加边界误差，并最小化来自分类校准损失理论的可微上界，显式地在鲁棒性与准确率之间做权衡。<sup>[15](https://proceedings.mlr.press/v97/zhang19p.html)</sup>

**Free对抗训练**回收反向传播的梯度来同时更新模型权重和扰动，在CIFAR-10和CIFAR-100上以可忽略的额外代价达到与PGD训练相当的鲁棒性，且运行速度比其他强对抗训练方法快7到30倍。<sup>[8](https://proceedings.neurips.cc/paper/2019/file/7503cfacd12053d309b6bed5c89de212-Paper.pdf)</sup> **快速对抗训练**使用带随机初始化的FGSM，以更低代价匹配基于PGD的训练；它还识别出灾难性过拟合是早期FGSM训练无法抵御PGD攻击的原因。<sup>[16](https://arxiv.org/abs/2001.03994v1)</sup> Free-TRADES将free-AT框架与TRADES结合，在相当或更好的测试性能下改善了泛化差距。<sup>[17](https://arxiv.org/html/2404.08980)</sup> **生成对抗训练器**则训练一个生成器网络从图像梯度产生扰动，与分类器交替训练；它随分类器训练而自适应，但比FGSM训练耗时多3到4倍。<sup>[18](https://arxiv.org/pdf/1705.03387v3.pdf)</sup>

WGAN用Wasserstein-1距离替代标准GAN目标的Jensen–Shannon散度准则以缓解梯度消失，WGAN-GP用梯度惩罚对评价网络施加Lipschitz约束，SNGAN用谱归一化层稳定训练。<sup>[19](https://ar5iv.labs.arxiv.org/html/2008.03364)</sup> FastGAN将Free对抗训练应用于GAN，用一次反向传播更新判别器和扰动，仅在2-4块GPU上即可在完整ImageNet上训练。<sup>[19](https://ar5iv.labs.arxiv.org/html/2008.03364)</sup>

## 应用

在ImageNet上经对抗训练的Inception v3在对抗样本上达到最高74%的top-1和92%的top-5准确率，同时在干净样本上仅损失约0.8%。<sup>[7](https://research.google/pubs/adversarial-machine-learning-at-scale/)</sup>在生成方面，[CycleGAN](https://www.edgepedia.org/zh/cyclegan)通过两个映射加循环一致性损失\( L_{\mathrm{cyc}} = \mathbb{E}_x[\|F(G(x)) - x\|_1] + \mathbb{E}_y[\|G(F(y)) - y\|_1] \)学习非配对图像到图像的转换，并用最小二乘损失替代负对数似然GAN目标以提升稳定性。<sup>[20](https://arxiv.org/pdf/1703.10593)</sup>对于大语言模型，潜空间对抗训练（谢沙德里及其同事，2024）针对LLM中持续的有害行为。<sup>[21](https://doi.org/10.48550/arxiv.2407.15549)</sup>对于视觉-语言模型，对CLIP进行对抗微调，在\( \epsilon = 1/255 \)下的PGD-10、CW-10和AutoAttack下，跨14个数据集达到平均零样本鲁棒准确率35.61%至38.39%。<sup>[22](https://arxiv.org/abs/2604.11576)</sup>

## 局限与替代方案

在FGSM样本上训练会导致标签泄露，即模型在对抗图像上的表现优于干净图像，并对受限的FGSM样本集过拟合，对PGD的鲁棒性很差；古德费洛等人2014年的MNIST模型在\( \epsilon = 0.3 \)下、10,000样本测试集上泄露79个标签。<sup>[4](https://arxiv.org/pdf/1706.06083v4.pdf)</sup><sup> • </sup><sup>[7](https://research.google/pubs/adversarial-machine-learning-at-scale/)</sup>对抗训练对单步攻击有帮助，但对迭代攻击帮助小得多。<sup>[7](https://research.google/pubs/adversarial-machine-learning-at-scale/)</sup>快速对抗训练可能因灾难性过拟合而失败，<sup>[16](https://arxiv.org/abs/2001.03994v1)</sup>而普通对抗训练过拟合严重：其鲁棒准确率泛化差距在\( \ell_2 \)攻击下超过30%，在\( \ell_{\infty} \)攻击下超过50%，free AT将其降至约20%。<sup>[17](https://arxiv.org/html/2404.08980)</sup>一项综述记录，防御性蒸馏——当时最先进的防御——在一年内被卡利尼和瓦格纳攻击攻破，且某些单步对抗训练方法产生梯度掩蔽，某些攻击可绕过。<sup>[23](https://arxiv.org/pdf/1911.05268)</sup><sup> • </sup><sup>[32](https://www.cs.purdue.edu/homes/bb/2020-fall-cs590bb/docs/at/adversarial_training.pdf)</sup>

作为可认证的替代方案，随机平滑通过添加噪声并界定类别概率来认证鲁棒性，但对于一大类分布，\( \sqrt{d} \)的依赖关系无法避免，这表明高维图像上\( \ell_{\infty} \)认证存在固有局限，<sup>[24](https://proceedings.neurips.cc/paper_files/paper/2024/file/f1e7c90552850afcc2558d78950c519d-Paper-Conference.pdf)</sup>且用ResNet-50认证一个ImageNet样本在100,000个蒙特卡洛样本下可能需要长达110秒。<sup>[25](https://ar5iv.labs.arxiv.org/html/2102.05096)</sup>基于凸松弛的认证训练在大多数任务上标准误差和鲁棒误差均劣于对抗训练，CIFAR-10上标准误差差距高达25%，Tiny ImageNet上高达35%，且无法扩展到ImageNet；\( \ell_{\infty} \)下\( \epsilon = 0.1 \)的MNIST是例外，最佳松弛优于对抗训练。<sup>[26](https://export.arxiv.org/pdf/2306.06995v1.pdf)</sup>扩散净化防御如DiffPure需要数十倍的推理计算，<sup>[27](https://proceedings.mlr.press/v202/wang23ad/wang23ad.pdf)</sup>且在修正的精确梯度计算下，其报告的鲁棒性基本消失：CIFAR-10鲁棒准确率在AutoAttack-\( \ell_{\infty} \)下至少下降27.73个百分点至8.59%。<sup>[28](https://arxiv.org/html/2411.16598v1)</sup>

近期工作将生成模型反馈到对抗训练中：用更高质量的EDM生成数据替代DDPM生成数据，在CIFAR-10和CIFAR-100上创下新的最先进AutoAttack鲁棒准确率，<sup>[27](https://proceedings.mlr.press/v202/wang23ad/wang23ad.pdf)</sup>并用5000万内部生成的[扩散](https://www.edgepedia.org/zh/diffusion)样本加模型扩展进行对抗训练，在ImageNet上\( \epsilon = 4/255 \)的AutoAttack下达到71.54%的\( \ell_{\infty} \)鲁棒准确率。<sup>[29](https://openaccess.thecvf.com/content/ICCV2025/papers/Wu_Scaling_and_Taming_Adversarial_Training_with_Synthetic_Data_ICCV_2025_paper.pdf)</sup>对于大语言模型，后续工作将每步对抗训练的FLOPs平均减少48.1%，因为仅8步内层PGD攻击就占潜空间对抗训练计算的约80%。<sup>[30](https://arxiv.org/pdf/2607.28959.pdf)</sup>对于视觉-语言模型，大规模多模态对抗预训练——而非仅单模态规模——是鲁棒性迁移到多模态LLM的关键因素，而直接对非鲁棒MLLM应用对抗训练会同时降低干净和对抗性能。<sup>[31](https://arxiv.org/abs/2606.03713)</sup>

## References

1. [Intriguing properties of neural networks (Szegedy et al.)](https://arxiv.org/pdf/1312.6199)
2. [Explaining and Harnessing Adversarial Examples (Goodfellow, Shlens, Szegedy, ICLR 2015)](https://arxiv.org/abs/1412.6572)
3. [Generative Adversarial Nets (Goodfellow et al., NeurIPS 2014)](https://proceedings.neurips.cc/paper_files/paper/2014/file/f033ed80deb0234979a61f95710dbe25-Paper.pdf)
4. [Towards Deep Learning Models Resistant to Adversarial Attacks (Madry et al.)](https://arxiv.org/pdf/1706.06083v4.pdf)
5. [Phase Transition from Clean Training to Adversarial Training](https://www.proceedings.com/content/068/068431-0678open.pdf)
6. [Adversarial Training Can Hurt Generalization (Raghunathan, Xie et al., ICML 2019 workshop)](https://par.nsf.gov/servlets/purl/10113528)
7. [Adversarial Machine Learning at Scale (Kurakin, Goodfellow, Bengio, ICLR 2017)](https://research.google/pubs/adversarial-machine-learning-at-scale/)
8. [Adversarial Training for Free! (Shafahi et al., NeurIPS 2019)](https://proceedings.neurips.cc/paper/2019/file/7503cfacd12053d309b6bed5c89de212-Paper.pdf)
9. [On the Convergence and Robustness of Adversarial Training (Wang et al., ICML 2019)](https://proceedings.mlr.press/v97/wang19i.html)
10. [Adversarial Robustness: Theory and Practice (tutorial slides, Kolter & Madry)](https://adversarial-ml-tutorial.org/adversarial_ml_slides_parts_2_3.pdf)
11. [Adversarial Training Methods for Deep Learning: A Systematic Review (Algorithms 2022)](https://www.mdpi.com/1999-4893/15/8/283)
12. [Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations (NIST AI 100-2, 2023)](https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-2e2023.pdf?6c620d40_page=1)
13. [Adversarial machine learning (Huang, Joseph, Nelson, Rubinstein, Tygar; AISec 2011)](https://dl.acm.org/doi/10.1145/2046684.2046692)
14. [Security Matters: A Survey on Adversarial Machine Learning (2018)](https://arxiv.org/pdf/1810.07339)
15. [Theoretically Principled Trade-off between Robustness and Accuracy (TRADES, Zhang et al., ICML 2019)](https://proceedings.mlr.press/v97/zhang19p.html)
16. [Fast is better than free: Revisiting adversarial training (Wong et al., fast adversarial training)](https://arxiv.org/abs/2001.03994v1)
17. [Stability and Generalization in Free Adversarial Training (2024)](https://arxiv.org/html/2404.08980)
18. [Generative Adversarial Trainer: Defense to Adversarial Perturbations with GAN](https://arxiv.org/pdf/1705.03387v3.pdf)
19. [Improving the Speed and Quality of GAN by Adversarial Training (FastGAN)](https://ar5iv.labs.arxiv.org/html/2008.03364)
20. [Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks (CycleGAN)](https://arxiv.org/pdf/1703.10593)
21. [Sheshadri, Abhay and colleagues (2024). Latent Adversarial Training Improves Robustness to Persistent Harmful Behaviors in LLMs. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2407.15549)
22. [Finetune Like You Pretrain: Boosting Zero-shot Adversarial Robustness in Vision-language Models (AdvFLYP)](https://arxiv.org/abs/2604.11576)
23. [Security Matters... / A Survey on Adversarial Machine Learning in the Visual Domain (2019)](https://arxiv.org/pdf/1911.05268)
24. [Adaptive Randomized Smoothing: Certified Adversarial Robustness for Multi-Step Defences (NeurIPS 2024)](https://proceedings.neurips.cc/paper_files/paper/2024/file/f1e7c90552850afcc2558d78950c519d-Paper-Conference.pdf)
25. [Towards Bridging the gap between Empirical and Certified Robustness against Adversarial Examples](https://ar5iv.labs.arxiv.org/html/2102.05096)
26. [On the Limitations of Certified Training (and the error gap with adversarial training)](https://export.arxiv.org/pdf/2306.06995v1.pdf)
27. [Better Diffusion Models Further Improve Adversarial Training (ICML 2023)](https://proceedings.mlr.press/v202/wang23ad/wang23ad.pdf)
28. [Unlocking The Potential of Adaptive Attacks on Diffusion-Based Purification](https://arxiv.org/html/2411.16598v1)
29. [Scaling and Taming Adversarial Training with Synthetic Data (ICCV 2025)](https://openaccess.thecvf.com/content/ICCV2025/papers/Wu_Scaling_and_Taming_Adversarial_Training_with_Synthetic_Data_ICCV_2025_paper.pdf)
30. [Efficient LLM Adversarial Training via Low-Rank Defense and Circuit-Guided Surrogates](https://arxiv.org/pdf/2607.28959.pdf)
31. [Investigating Adversarial Robustness of Multi-modal Large Language Models (BMVC 2026)](https://arxiv.org/abs/2606.03713)
32. [cs.purdue.edu](https://www.cs.purdue.edu/homes/bb/2020-fall-cs590bb/docs/at/adversarial_training.pdf)

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

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

Copyright 2026 Edgepedia

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

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

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