Search

Search papers and lessons

Towards Evaluating the Robustness of Neural Networks

Nicholas Carlini, David Wagner · 2016

Carlini and Wagner built three attacks that find adversarial examples on every test image, including networks hardened by defensive distillation, and so set a stronger bar for defenses.

On this page

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

TL;DR

Neural networks can be fooled by inputs that differ from a normal input by an amount too small for a person to notice. A defense called defensive distillation had cut the success rate of the attacks known at the time from 95% to 0.5%. Carlini and Wagner built three new attacks, one for each of the common distance measures L0L_0, L2L_2 and L∞L_\infty, and each succeeded with 100% probability on the images the paper tested, on both the distilled and the ordinary network. The paper's lasting contribution is a standard for defenses: test them against strong attacks before trusting them.

Builds on: Adversarial Examples, Constrained Optimization, Cross-Entropy Loss, Softmax · Leads to: the attack-evaluation practice used for later defenses, and Adversarial Training as a method whose claims are judged against such attacks

Why it mattered

Adversarial examples were known since 2013, but defensive distillation in 2016 looked like a real fix for a network that could be trained in one extra pass. The paper showed that the apparent security came from weak attacks rather than from a robust network. The attacks were released as code, and the authors recommended that anyone proposing a defense first check whether it resists these attacks, and whether its high-confidence adversarial examples transfer to the defended model.

The paper also changed how people talk about robustness. A defense that stops a weak attack says little. A defense is only meaningful when it survives an attack that is strong enough, and the paper gave concrete attacks that could serve as that test.

The problem

A classifier FF assigns an input xx a label. An adversarial example is a new input x′x' that is close to xx under some distance, but is labeled with a chosen target class tt. Robustness means how far the nearest adversarial example is. The difficulty is that the attacker must find a point that both looks like xx and gets the target label, and the classifier's output is a smooth function that is hard to push toward a specific label.

Before this paper, the attacks used to test defenses had three weaknesses. They were often fast but found large distortions. Some failed completely on hardened networks. And they were fragile: as Section VIII-A shows, they could fail even when adversarial examples existed, so a failure did not prove the network was safe. Defensive distillation seemed to defeat the attacks of the time, which made it look robust, but the authors showed the attacks were failing for reasons that had nothing to do with robustness.

How it works

The method turns the attack into a numerical optimization problem, then solves it with gradient descent. Here is the walkthrough for one target, with the L2L_2 attack, which is the one the paper relies on most.

  1. Choose a source image and a target class. Start from an image xx with correct label C∗(x)C^*(x), and pick a target class tt different from it. Check: the attack must make the network output tt for the changed image x′x'.
  2. Measure distortion. Use the squared L2L_2 distance ∥x′−x∥22\|x' - x\|_2^2, the sum of squared pixel changes. Check: moving one pixel from 0 to 0.5 costs 0.250.25, and moving it from 0 to 1 costs 11.
  3. Measure how far the target is from winning. Let Z(x′)Z(x') be the logits, the network's scores before softmax. The loss ff is positive while some other class has a higher score than class tt, and stops decreasing once tt leads by a margin. Check: with margin 00, if ZtZ_t is already the largest score, ff equals 00.
  4. Keep pixels in range. Write each pixel as 12(tanh⁡(w)+1)\tfrac{1}{2}(\tanh(w) + 1), where ww is an unconstrained number. Any real ww gives a pixel in (0,1)(0, 1), so no box constraint is needed. Check: w=0w = 0 gives pixel 0.50.5.
  5. Trade off distortion against success. Minimise ∥x′−x∥22+c⋅f(x′)\|x' - x\|_2^2 + c \cdot f(x') over ww with gradient descent. The constant cc sets the balance: a larger cc puts more weight on success. Check: with cc too small the example stays on the original class; with cc too large it is far from xx.
  6. Search over cc. Use binary search over cc, and for each value run gradient descent with the Adam optimizer. Keep the smallest distortion that still succeeds. Check: the search stops at a cc that is large enough to succeed and as small as possible.
  7. Restart from several points. Start gradient descent from several random points near the best example found so far, to avoid getting stuck in a poor local minimum.
flowchart LR
  A["Image x, target t"] --> B["Reparametrise pixels with tanh"]
  B --> C["Minimise distortion + c times f"]
  C --> D{"Target wins?"}
  D -- no --> E["Adjust c with binary search"]
  E --> C
  D -- yes --> F["Keep the smallest distortion found"]

A tiny trace of step 4. Take w=1w = 1. Then tanh⁡(1)≈0.7616\tanh(1) \approx 0.7616, so the pixel is 12(0.7616+1)≈0.8808\tfrac{1}{2}(0.7616 + 1) \approx 0.8808. Take w=−1w = -1. The pixel is 12(−0.7616+1)≈0.1192\tfrac{1}{2}(-0.7616 + 1) \approx 0.1192. Both values stay inside [0,1][0, 1] without any clipping step.

The math

Definition: Targeted adversarial example

Given an input xx with correct label C∗(x)C^*(x), a target t≠C∗(x)t \neq C^*(x), and a distance DD, a targeted adversarial example is an input x′x' with C(x′)=tC(x') = t that minimises D(x,x′)D(x, x') among inputs of the same kind. Here C(x′)=arg⁡max⁡iF(x′)iC(x') = \arg\max_i F(x')_i.

The paper uses the LpL_p norm ∥v∥p=(∑i∣vi∣p)1/p\|v\|_p = \left(\sum_i |v_i|^p\right)^{1/p}, with L0L_0 counting changed pixels, L2L_2 the Euclidean length of the change, and L∞L_\infty the largest single change. All pixel values lie in [0,1][0, 1], so changing one pixel from fully on to fully off has L2=1L_2 = 1 and L∞=1L_\infty = 1.

Step 2 in symbols: the distance

∥x′−x∥22=∑i=1n(xi′−xi)2.\|x' - x\|_2^2 = \sum_{i=1}^{n} (x'_i - x_i)^2.

Step 3 in symbols: the margin loss

Let Z(x′)iZ(x')_i be the logit of class ii. The paper's loss is

f(x′)=max⁡(max⁡i≠tZ(x′)i−Z(x′)t,  −κ).f(x') = \max\left(\max_{i \neq t} Z(x')_i - Z(x')_t,\; -\kappa\right).

The inner term is positive while some other class leads tt. It becomes negative once tt leads by more than κ\kappa, and the outer max stops the loss from falling below −κ-\kappa. The paper sets κ=0\kappa = 0 for its main attacks. Raising κ\kappa asks for a more confident misclassification, which the transferability experiment uses.

Step 4 in symbols: the change of variables

x′=12(tanh⁡(w)+1).x' = \tfrac{1}{2}\big(\tanh(w) + 1\big).

The function tanh⁡\tanh has range (−1,1)(-1, 1), so xi′x'_i lies in (0,1)(0, 1) for every real wiw_i. This is why the paper can drop the box constraint and use an unconstrained optimiser. The same identity gives 12(tanh⁡(w)+1)=σ(2w)\tfrac{1}{2}(\tanh(w) + 1) = \sigma(2w), where σ\sigma is the logistic sigmoid.

Step 5 in symbols: the full problem

min⁡w  ∥12(tanh⁡(w)+1)−x∥22+c⋅f ⁣(12(tanh⁡(w)+1)).\min_w \; \left\| \tfrac{1}{2}\big(\tanh(w) + 1\big) - x \right\|_2^2 + c \cdot f\!\left(\tfrac{1}{2}\big(\tanh(w) + 1\big)\right).

The first term keeps the example close to xx. The second pushes it to class tt. The constant c>0c > 0 balances them.

Step 6 in symbols: choosing c

For each candidate cc, the paper runs the minimiser and records whether the target is reached. Binary search over cc finds the smallest value that succeeds. The paper reports 20 binary-search steps, each with 10,000 Adam iterations. It notes that Adam reaches 95% of the optimum within 1,000 iterations in 92% of runs.

Worked examples

Example
1. One pixel, one target (tiny)

A toy image has one pixel with value x=0.5x = 0.5. We want the change to give target tt, and we try w=0w = 0 and w=2w = 2.

  1. Start with w=0w = 0. Then tanh⁡(0)=0\tanh(0) = 0, so x′=12(0+1)=0.5x' = \tfrac{1}{2}(0 + 1) = 0.5.
  2. The change is x′−x=0x' - x = 0, so the distance is 00.
  3. Now try w=2w = 2. Then tanh⁡(2)≈0.9640\tanh(2) \approx 0.9640, so x′=12(0.9640+1)≈0.9820x' = \tfrac{1}{2}(0.9640 + 1) \approx 0.9820.
  4. The change is about 0.48200.4820, so the squared L2L_2 distance is about 0.23230.2323.
  5. Check: 0.48202≈0.23230.4820^2 \approx 0.2323.
  6. Interpretation: the transform keeps every candidate in (0,1)(0, 1), and a larger ww moves the pixel further from the original. The optimiser trades this distance against the margin loss.
Example
2. The MNIST model, the standard case

Table IV of the paper reports the average L2L_2 distortion of the targeted attack on the undistilled MNIST network, with the target chosen at random. The paper's convention puts pixel values in [0,1][0, 1].

  1. The average-case mean for MNIST is 1.76, with success probability 100%.
  2. The best-case mean is 1.36, and the worst-case mean is 2.60, both with success 100%.
  3. The best previously reported L2L_2 attack in the same table, DeepFool, has a best-case mean of 2.11 on MNIST.
  4. Ratio: 2.11/1.36≈1.552.11 / 1.36 \approx 1.55. On this best-case MNIST row the new attack needs about 1.55 times less distortion than DeepFool.
  5. Interpretation: the paper's general claim, that its L0L_0 and L2L_2 attacks need 2 to 10 times lower distortion than the best previous attacks, covers all the comparisons together. This one row shows a smaller gap, so read the claim against the individual rows.
Example
3. Distilled networks, the realistic case

Defensive distillation trains the network at temperature T=100T = 100. Table VI reports the L2L_2 attack on distilled networks.

  1. On distilled MNIST the mean L2L_2 distortions are 1.7 (best case), 2.2 (average case) and 2.9 (worst case). Each has success probability 100%.
  2. On the same undistilled network (Table IV), the means were 1.36, 1.76 and 2.60.
  3. On average the distilled network needs about 25% more distortion, comparing 2.2 with 1.76.
  4. Check: 2.2/1.76=1.252.2 / 1.76 = 1.25.
  5. The previous attacks, which the paper says all fail on distilled networks, are the reason distillation had looked strong. The new attack succeeds on every image, so the distilled network gave only a small increase in distortion.
  6. Interpretation: distillation adds a little distance but does not stop an attack that is willing to search longer.

Try it: Table IV gives a worst-case L2L_2 mean of 0.51 for the undistilled CIFAR network and Table VI gives 0.92 for the distilled one. By what factor did the distilled distortion rise?

Answer: 0.92/0.51≈1.800.92 / 0.51 \approx 1.80. The distilled network needs about 1.8 times the distortion in the worst case.

Results

Attack strength against the undistilled networks (Table IV). On MNIST and CIFAR-10, every new L2L_2 attack succeeded on every target, with mean distortions of 1.36 to 2.60 on MNIST and 0.17 to 0.51 on CIFAR-10 across the best, average and worst cases. The fast gradient sign method failed on some cases; on the worst case for MNIST it succeeded 0% of the time, and on the average and worst cases for CIFAR-10 its success rate fell to 51% and 1%.

Attack strength on ImageNet (Table V). The paper used the pre-trained Inception v3 network, which has 96% top-5 accuracy. The L2L_2 attack found untargeted adversarial examples with mean distortion 0.32, and the least-likely-target variant reached 2.22, both with success probability 100%. JSMA could not run on ImageNet at all within the paper's setup, so the paper reports it as failing.

Attacks on distillation (Table VI). Each of the three new attacks succeeded on 100% of cases on distilled networks. The L2L_2 means were close to the undistilled values: the paper concluded that distillation "has added almost no value."

Temperature. The paper cites the original work for a drop in attack success on MNIST from 91% at T=1T = 1, to 24% at T=5T = 5, to 0.5% at T=100T = 100. With its own attack, the mean L2L_2 distance was uncorrelated with temperature, with correlation coefficient ρ=−0.05\rho = -0.05. Higher temperature therefore made the old attacks fail, not the network safer.

Transferability. Adversarial examples built on one ordinary MNIST model transferred to a second ordinary model with success rising with the margin κ\kappa, reaching near 100% at κ≈20\kappa \approx 20. Transfer to the distilled model reached 100% only at κ=40\kappa = 40. This gives a second, separate test that the authors recommend.

Models used. The MNIST network reached 99.5% accuracy, comparable to the state of the art, and the CIFAR-10 network 80%, identical to the accuracy in the original distillation work. The CIFAR-10 model overfits: training accuracy was 98% against 80% on validation.

Limits. The paper gives upper bounds on robustness, not proofs. The distance measures are imperfect models of human perception, which the paper says it does not settle. The ImageNet best and worst cases are estimated from 100 random target classes out of 1,000. Some earlier attacks are compared using numbers from their papers and others are re-implemented by the authors, and the paper notes that results across different models are not directly comparable.

Reading guide

Check yourself

QuestionWhy does the paper replace the box constraint on pixels with the change of variables 12(tanh⁡(w)+1)\tfrac{1}{2}(\tanh(w)+1)?Show answer

Because tanh⁡(w)\tanh(w) takes values in (−1,1)(-1, 1) for every real ww, so 12(tanh⁡(w)+1)\tfrac{1}{2}(\tanh(w) + 1) always lies in (0,1)(0, 1). The optimiser can then work over all real ww with plain gradient descent, and no clipping or constrained solver is needed.

QuestionFor the pixel w=−2w = -2, compute 12(tanh⁡(w)+1)\tfrac{1}{2}(\tanh(w)+1) to two decimal places, given tanh⁡(2)≈0.96\tanh(2) \approx 0.96.Show answer

tanh⁡(−2)=−tanh⁡(2)≈−0.96\tanh(-2) = -\tanh(2) \approx -0.96. So the pixel is 12(−0.96+1)=0.02\tfrac{1}{2}(-0.96 + 1) = 0.02. This is close to 0, as expected for a very negative ww.

QuestionThe margin loss uses κ=0\kappa = 0 in the main experiments. What does a larger κ\kappa change, and why is it useful?Show answer

A larger κ\kappa keeps the loss from reaching its floor until the target class leads by at least κ\kappa. The optimiser then produces examples that the network puts in class tt with more confidence. The paper uses this to build high-confidence examples that transfer to a distilled network, which needs κ=40\kappa = 40 rather than κ=20\kappa = 20.

QuestionA new defense reduces the success of the fast gradient sign method from 95% to 2%. Why does the paper say this is not enough evidence that the defense is robust?Show answer

Because the paper showed that the older attacks can fail on a defended network even when adversarial examples exist, as with distillation. Success on a weak attack says little about the strongest attack. The paper's recommendation is to test the defense against a strong attack such as its L2L_2 method, and to check whether high-confidence examples transfer to the defended model.

Sources

Read the full paper

Nicholas Carlini, David Wagner, 2016. arXiv:1608.04644