Search

Search papers and lessons

Towards Deep Learning Models Resistant to Adversarial Attacks

Aleksander Madry, Aleksandar Makelov, Ludwig Schmidt et al. · 2017

Madry et al. (2017) cast robustness as a min-max problem, attack with projected gradient descent, and train on those attacks; the MNIST model keeps about 89 percent accuracy under the strongest attack tested.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Losses & regularization
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

A neural network can be fooled by an input changed by an amount too small for a person to notice. Earlier defences often lacked a clear guarantee, because nobody could be sure the attack used to test them was the strongest. This paper frames robustness as a min-max problem: the model is trained to do well on the worst allowed change to each input. The worst change is found with projected gradient descent (PGD), a multi-step attack. Training on PGD examples gives networks that resist a wide range of attacks. On MNIST the authors report more than 89 percent accuracy against the strongest attack in their test suite, and 46 percent on CIFAR-10.

Builds on: Adversarial Training, Fast Gradient Sign Method, Constrained Optimization · Leads to: Adversarial Training (the PGD form that became the standard baseline)

Why it mattered

The paper names security-critical uses of classifiers, including vision for autonomous cars, face recognition and malware detection, and any of them faces the threat it describes. The paper's central hope, that a model robust to PGD is also robust to other gradient-based attacks, is stated as a conjecture and tested in its experiments. Its framing also changes how an attack is seen: an attack is a strong optimisation problem to be solved well, not a single recipe to be tried once.

Adversarial training before this paper

The idea of training on adversarial inputs predates this paper. The paper's related-work section says adversarial training was introduced with the fast gradient sign method, which is a one-step attack. That attack is weak against iterative adversaries, so networks trained on it were still vulnerable to multi-step attacks.

The problem

Write θ\theta for the model parameters, L(θ,x,y)L(\theta, x, y) for the loss on input xx with label yy, and S\mathcal{S} for the set of allowed changes. Standard training minimises the average loss on clean inputs. The paper asks for a classifier whose loss stays small on every allowed change of every input, so it proposes the saddle point problem (the paper's equation 2.1). Its two parts are hard for different reasons.

The inner maximisation is non-concave. Finding the worst allowed change for one input is maximising a function that has many local maxima, so it could look intractable. Earlier work avoided this by linearising the inner problem, which gives one-step attacks such as the fast gradient sign method.

The outer minimisation is non-convex. Training a deep network is already non-convex. The question is whether gradient steps on the adversarial loss still make progress when the inner problem is only solved approximately.

The paper answers both questions experimentally and with a theorem from optimisation, and it then uses those answers to train networks.

How it works

The method has three parts: a worst-case attack, a check that the attack is strong, and training on its outputs. The walkthrough below uses a one-dimensional toy in place of an image, because the paper's own numbers come later.

  1. Fix an allowed region. Take the input x=0.5x = 0.5 and a budget ε=0.1\varepsilon = 0.1. The allowed inputs form the interval from 0.4 to 0.6. Check: the interval has width 2ε=0.22\varepsilon = 0.2.
  2. Pick a loss to maximise. Use L(x′)=(x′−0.8)2L(x') = (x' - 0.8)^2. The attacker wants LL large, which means x′x' far from 0.8. Check: at x′=0.4x' = 0.4 the loss is 0.16, and at x′=0.6x' = 0.6 it is 0.04, so 0.4 is the worst point in the interval.
  3. Start at a random point. The paper restarts from random points in the allowed region. Start at x0=0.55x_0 = 0.55, where L=0.0625L = 0.0625.
  4. Take a signed gradient step. The gradient is 2(x−0.8)=−0.52(x - 0.8) = -0.5, which is negative, so the sign step with α=0.05\alpha = 0.05 moves to x1=0.50x_1 = 0.50, where L=0.09L = 0.09. Check: the loss went up.
  5. Repeat, and project back. Steps continue to 0.450.45 (L=0.1225L = 0.1225) and to 0.400.40 (L=0.16L = 0.16). The next step would give 0.35, outside the region, so the projection Π\Pi returns it to 0.40. Check: the loss stops rising at its maximum over the interval.
  6. Train on the attacked input. Compute the loss at the final point, x=0.40x = 0.40, and take a gradient step on the model parameters using that point. Repeat for many inputs and many epochs. The paper argues the model improves because each gradient is taken at a near-worst case.

Diagram of one training step on a batch:

flowchart LR
  B["clean batch"] --> P["PGD: random start, signed steps, projection"]
  P --> A["adversarial batch"]
  A --> G["gradient of loss at adversarial inputs"]
  G --> U["SGD update of model parameters"]
  U -->|"next batch"| B

The math

The saddle point problem

The central object is the min-max problem. The paper writes it as

min⁡θρ(θ),ρ(θ)=E(x,y)∼D[max⁡δ∈SL(θ,x+δ,y)]\min_{\theta}\rho(\theta),\qquad \rho(\theta)=\mathbb{E}_{(x,y)\sim\mathcal{D}}\left[\max_{\delta\in\mathcal{S}} L(\theta, x+\delta, y)\right]

Here D\mathcal{D} is the data distribution and δ\delta is the perturbation. The inner maximum is the attack, and the outer minimum is the training. The paper uses S\mathcal{S} as the ℓ∞\ell_\infty ball of radius ε\varepsilon: every coordinate of δ\delta lies between −ε-\varepsilon and ε\varepsilon.

Step 2 in symbols: the inner attack

The one-step fast gradient sign method sets

x+ε sgn⁡(∇xL(θ,x,y))x + \varepsilon\,\operatorname{sgn}\left(\nabla_x L(\theta, x, y)\right)

where sgn⁡\operatorname{sgn} takes the sign of each coordinate. The multi-step projected gradient descent attack iterates

xt+1=Πx+S(xt+α sgn⁡(∇xL(θ,xt,y)))x^{t+1} = \Pi_{x+\mathcal{S}}\left(x^{t} + \alpha\,\operatorname{sgn}\left(\nabla_x L(\theta, x^{t}, y)\right)\right)

with step size α\alpha and projection Π\Pi onto the allowed set. In the toy of the walkthrough, α=0.05\alpha = 0.05 and the projection clips to the interval [0.4,0.6][0.4, 0.6].

Step 3 in symbols: the outer update

Differentiating the inner maximum is the key point. Danskin's theorem says that, for a maximum over a compact set of a smooth function, the gradient of the maximum equals the gradient at the maximiser when that maximiser is unique. The paper therefore takes the gradient of the loss at the adversarial input xˉ=x+δˉ\bar{x} = x + \bar{\delta}:

∇θρ(θ)≈∇θL(θ,x+δˉ,y)\nabla_\theta \rho(\theta) \approx \nabla_\theta L(\theta, x+\bar{\delta}, y)

and a gradient step on θ\theta using δˉ\bar{\delta} is a descent direction for ρ\rho. The paper notes that the theorem's assumptions fail in practice, because ReLU and max-pooling are not smooth, and the inner maxima are approximate. Its experiments suggest that the training still works well enough in practice, and that the value of the saddle point problem falls as capacity grows.

Worked examples

Example
One FGSM step on the toy (tiny)
  1. Start from x=0.55x = 0.55, where L=0.0625L = 0.0625, and the gradient is −0.5-0.5.
  2. The sign of the gradient is −1-1. The fast gradient sign step is x+εsgn⁡(∇)x + \varepsilon\operatorname{sgn}(\nabla), which is 0.55−0.1×1=0.450.55 - 0.1 \times 1 = 0.45.
  3. The loss at 0.45 is (0.45−0.8)2=0.1225(0.45 - 0.8)^2 = 0.1225.
  4. Interpretation: one large step reaches 0.45. Iterated PGD reaches 0.40 and a loss of 0.16, so the multi-step attack finds a stronger point, which is the paper's reason for preferring PGD.
Example
Clean accuracy against the strongest MNIST attack (standard)

The paper reports that a standard MNIST network reaches 99.2 percent accuracy on clean inputs, and that FGSM at ε=0.3\varepsilon = 0.3 drops it to 6.4 percent.

  1. Compute the drop for the standard network under FGSM: 99.2−6.4=92.899.2 - 6.4 = 92.8 percentage points.
  2. The adversarially trained MNIST network has clean accuracy 98.8 percent in Table 1, and 89.3 percent under PGD with 100 steps and 20 restarts, the strongest white-box attack in the table.
  3. Compute its drop: 98.8−89.3=9.598.8 - 89.3 = 9.5 percentage points.
  4. Interpretation: the robust network loses 9.5 points to its strongest attack, while the standard network loses 92.8 to FGSM. The clean-accuracy cost in this table is small.
  5. Caution: the two numbers come from different attacks, FGSM on the standard network and PGD on the robust one. The comparison shows the scale of the effect, not a controlled gain from one change.
Example
A realistic trade-off on CIFAR-10 (realistic)

Appendix Table 5 lists, for the wide architecture, a standard network and a PGD-trained network at ε=8\varepsilon = 8. The standard network has 95.2 percent clean accuracy and 3.5 percent under 20-step PGD. The PGD-trained network has 87.3 percent clean and 45.8 percent under the same attack.

  1. Robustness gained: 45.8−3.5=42.345.8 - 3.5 = 42.3 points.
  2. Clean accuracy given up: 95.2−87.3=7.995.2 - 87.3 = 7.9 points.
  3. Interpretation: the defence costs about 8 points of clean accuracy and gains about 42 points under the iterative attack. The paper still calls the CIFAR-10 robustness "far from satisfactory".

Try it: a model has 94.0 percent clean accuracy and 10.0 percent under PGD, and a second model has 88.0 percent clean and 40.0 percent under PGD. Which trade is better by the difference in each column? Answer: the second gains 30.0 points of robustness and loses 6.0 points of clean accuracy, so it is the larger trade, and whether it is better depends on how the application weighs clean accuracy against attack resistance.

Results

The paper reports results on MNIST and CIFAR-10, all with ℓ∞\ell_\infty-bounded perturbations, and each number below is copied from the paper's text or tables.

  • MNIST, white-box (Table 1). The network has two convolutional layers with 32 and 64 filters, each followed by 2×22 \times 2 max-pooling, and a fully connected layer of 1024 units. It was trained and tested at ε=0.3\varepsilon = 0.3 with 40 PGD steps of size 0.01. Clean accuracy is 98.8 percent. Accuracy under PGD with 100 steps and 20 restarts is 89.3 percent, and under PGD with 40 steps and 1 restart it is 93.2 percent.
  • MNIST, black-box (Table 1). Transfer from an independently trained copy of the network gives 95.7 percent under PGD with 100 steps and 20 restarts. From the architecture B of Tramer et al., the best attack gives 95.4 percent.
  • CIFAR-10, white-box (Table 2). Training used 7 PGD steps of size 2 at ε=8\varepsilon = 8. The wide network has 87.3 percent clean accuracy, 45.8 percent under 20-step PGD, which the introduction rounds to 46 percent. Under a Carlini-Wagner attack it gives 46.8 percent.
  • CIFAR-10, black-box (Table 2). Transfer from an independent copy gives 64.2 percent under 7-step PGD. The introduction reports 64 percent.
  • Capacity (Section 4). On MNIST the paper doubles the filter counts and hidden size, starting from 2 and 4 filters and a 64-unit layer. On CIFAR-10 a ResNet widened by a factor of 10 reaches 95.2 percent clean accuracy when trained on natural examples.
  • Learned MNIST filters (Appendix C). The robust network uses only 3 of its 32 first-layer filters, and each uses one non-zero weight, so each acts as a thresholding filter.
  • Limits. Results are for two datasets and one architecture family. The authors say the CIFAR-10 result is still far from satisfactory. On the ℓ2\ell_2 MNIST result, PGD fails to find attacks at ε=4.5\varepsilon = 4.5. The paper says later work found PGD overestimates this robustness, possibly because of gradient masking.

Common mistakes and tradeoffs

It is tempting to think that a model trained with FGSM is robust. In fact the paper finds that FGSM training makes the network overfit the one-step examples, a behaviour called label leaking. Those networks have poor clean accuracy and no robustness against PGD, because the one-step attack gives a narrow set of examples to memorise. FGSM is a reasonable training adversary only when ε\varepsilon is small, where the loss is nearly linear around each input.

It is tempting to think that the model is safe against all attacks once it resists PGD. In fact the paper treats PGD as its strongest first-order attack and conjectures that robustness to PGD carries over to other first-order attacks. That is a claim the experiments support, not a proof. Subsequent work found that PGD overestimates the ℓ2\ell_2 robustness of the paper's MNIST model, and the paper suggests this may come from learned threshold filters masking gradients.

It is tempting to think that capacity does not matter. In fact the paper finds that small networks trained against PGD can fail to learn at all, converging to always predicting one class. The authors conclude that robust classification needs more capacity than natural classification does.

Tradeoffs. PGD training costs many forward and backward passes per batch, for example 40 PGD iterations per step on MNIST in the paper. It also lowers clean accuracy, as the CIFAR-10 example shows. Use it when the threat is an ℓ∞\ell_\infty-bounded adversary and the model is large enough to carry both goals. Do not use it on a small model, or as the only check of robustness, since PGD can overestimate robustness when gradients are masked. Simpler alternatives are FGSM training, which is cheap but leaks labels, and standard training, which gives no robustness guarantee.

Reading guide

The paper's sections, in order, with the lessons each one needs.

Check yourself

QuestionWhy does the paper prefer a multi-step attack such as PGD over a single FGSM step when training?Show answer

A single step follows the gradient at one point and can land short of the worst case. In the toy, one FGSM step reaches a loss of 0.1225, while iterated PGD with projection reaches 0.16. Training on the stronger attack gives the model a harder target, which is why the paper argues PGD is the better inner solver.

QuestionThe standard MNIST network has 99.2 percent clean accuracy and 6.4 percent under FGSM at ε=0.3\varepsilon = 0.3. What is the drop in percentage points?Show answer

99.2−6.4=92.899.2 - 6.4 = 92.8 percentage points.

QuestionWhy does the paper find that training against FGSM fails, even though FGSM is a valid attack?Show answer

The one-step adversary produces a narrow set of examples, and the network overfits to them, a behaviour called label leaking. Those networks have poor clean accuracy and do not resist PGD, so the training matches the attack and not the robustness goal.

QuestionA paper says its model is robust to all first-order attacks. What is the difference between a conjecture and a proof here?Show answer

The paper conjectures that robustness to PGD extends to other first-order attacks and supports this with experiments on several attacks and transfer settings. A proof would show it for every such attack. Subsequent work found that PGD overestimates the ℓ2\ell_2 robustness of the paper's MNIST model, which the paper suggests may be due to gradient masking by its threshold filters.

QuestionIn the CIFAR-10 example, how many points of clean accuracy does the PGD-trained wide network give up, and how many does it gain against 20-step PGD?Show answer

It gives up 95.2−87.3=7.995.2 - 87.3 = 7.9 points of clean accuracy and gains 45.8−3.5=42.345.8 - 3.5 = 42.3 points of robustness, relative to the standard wide network.

Sources

Read the full paper

Aleksander Madry, Aleksandar Makelov, Ludwig Schmidt et al., 2017. arXiv:1706.06083