Algorithm Search⌘K

Techniqueadvanced

Expectation over transformation

Also called EOT.

Optimizes an adversarial example for the expected loss over random transformations such as rotation and lighting, so it works in the physical world.

Expectation over transformation (EOT) is a technique of Athalye, Engstrom, Ilyas and Kwok (2018) for finding an input change that fools a classifier not at one fixed view of the input but on average over a distribution TT of transformations tt, such as rotation, scaling, lighting, noise or a random step of a defense. The adversary maximizes Et∼T[log⁡P(ytarget∣t(x′))]E_{t \sim T}[\log P(y_{\text{target}} \mid t(x'))] under a bound on the expected distance Et∼T[d(t(x′),t(x))]E_{t \sim T}[d(t(x'), t(x))], and estimates the gradient of the expectation by the mean gradient over a few sampled tt, as in stochastic gradient descent. With it, the authors made 2D images that stayed adversarial under noise, distortion and affine transformations, and 3D-printed objects that a classifier labelled as the target class from most viewpoints. In the evaluation of defenses, EOT is the standard answer to randomness: a defense that adds a random step to the input has a random gradient, and an attack that uses one sample of it is too weak.

In plain words

An adversarial example usually works only for one exact picture. Turn it a little, change the light, or print it, and the trick stops working.

EOT asks for a change that works for many views at once. At each step it draws several random views of the current input, asks how to change the input to fool the model on all of them, and moves in the average direction. The result fools the model across the whole range of views.

The same idea tests defenses that use randomness. If a defense blurs or shifts the input at random, one gradient is noisy, but the average of many gradients still points the right way.

When it applies

  • The input reaches the model through a random transformation t∼Tt \sim T, either from the world (camera angle, distance, light) or from a random defense (random resizing, padding, noise, dropout at test time).
  • The attacker can sample from TT, or from a model of it, and tt is differentiable or has a usable stand-in, as with BPDA.
  • The goal is success on average or with high probability over tt, not for one fixed tt.
  • For a defense with a certificate over the randomness, such as randomized smoothing, EOT cannot beat the certified radius; it can only find inputs outside it.

The template

Notation: ff is the model, LL the loss of the adversary (for a target label, the negative log probability of the target), TT the distribution of transformations, SS the allowed set of inputs, and ΠS\Pi_S the projection onto it. The holes in angle brackets are chosen for each evaluation.

  1. EOT-EVALUATE(f, x, T, S)
  2. 1x' ← x
  3. 2for i ← 1 to ⟨number of steps⟩ do
  4. 3draw t_1, ..., t_m from T ▷ m = ⟨samples per step⟩
  5. 4g ← (1/m) Σ_j ∇_{x'} L(f(t_j(x'))) ▷ an unbiased estimate of ∇ E_t[L(f(t(x')))]
  6. 5x' ← Π_S(x' - ⟨step rule⟩(g)) ▷ a step of projected gradient descent on the expected loss
  7. 6return x' ▷ measure the success rate over fresh draws of t

Line L4 is the whole idea. Under mild conditions (for example a loss that is differentiable in x′x' for each tt, with a gradient bounded by an integrable function), the gradient of the expectation is the expectation of the gradient, so the mean over mm samples is an unbiased estimate with variance that falls like 1/m1/m. Line L5 is the same step as PGD or as the Lagrangian form of the paper, which adds the distance term to the loss. Line L6 must use new samples of tt, so that the reported success is not fitted to the samples used in the search.

Cost. Each step costs mm forward and backward passes. Evaluations of random defenses often need tens or hundreds of samples per step before the success rate stops growing.

What it measures. The result is an upper bound on the robust accuracy of the random system as a whole: the fraction of inputs for which the attack fails, averaged over the randomness. This is a measurement for one attack, not a guarantee.

Classic examples

  • A toy random defense. Let a defense add a random shift u∈{−0.2,0,0.2}u \in \{-0.2, 0, 0.2\}, each with probability 1/31/3, to a single input before the linear score s(v)=v−0.5s(v) = v - 0.5. At x=0.7x = 0.7 the scores are 00, 0.20.2 and 0.40.4, so the input is classified as positive (label 1 if s>0s > 0) with probability 2/32/3. One sampled gradient is always 11 here, so this defense does not hide the direction; but with a nonlinear ff the sampled gradients disagree, and their mean at line L4 is the gradient of the expected loss. Moving xx down to 0.50.5 makes the scores −0.2-0.2, 00 and 0.20.2, so the positive label survives with probability only 1/31/3.
  • Physical objects. Athalye et al. used a distribution over 3D poses, lighting and camera noise and changed the texture of 3D-printed objects so that an ImageNet classifier gave the target label from most viewpoints.
  • Random defenses of 2018. In Athalye, Carlini and Wagner (2018), defenses based on random input transformations and random pruning of activations fell to EOT, often together with BPDA.
  • Universal perturbations. A universal adversarial perturbation is the same objective with TT the distribution of the data: one change for many inputs.
  • Adversarial training under transformations. The defense side of the same objective trains the model on transformed adversarial inputs; see adversarial training.

Variations

  • A distance constraint in expectation. The paper bounds Et[d(t(x′),t(x))]E_t[d(t(x'), t(x))], for example the distance in a perceptual color space, so that the change stays small in every view.
  • More samples or more steps. When the gradient variance is high, increase mm at line L3 or run more steps; both cost forward passes.
  • Stand-ins for non-differentiable transformations. Use a differentiable renderer or BPDA for tt when it has no gradient.
  • Worst case over TT. Replace the expectation by a maximum over a finite set of transformations when the goal is success for every view, not on average.
  • Transfer across models. Averaging over an ensemble of models in place of transformations improves transferability.

Pitfalls

  • Too few samples. With m=1m = 1 at line L3, a random defense can look robust only because the gradient is noisy. Report the success rate as a function of mm and of the number of steps, and stop only when it stops growing.
  • A wrong model of TT. If the distribution used at line L3 differs from the real transformations, the result can fail in use. For defenses, sample from the exact randomness of the defense.
  • Evaluating on the search samples. Line L6 must draw fresh transformations; success on the samples of line L3 overstates the rate.
  • Fixing the random seed of the defense. Attacking one fixed draw of the defense's randomness gives a change that fits that draw only; the defense then appears robust to new draws for the wrong reason.
  • Reading the result as a lower bound. Like every attack, EOT gives an upper bound on robust accuracy. Only a verifier or a certificate gives a lower bound.

Exercises

  1. In the toy random defense, find the set of inputs xx for which the positive label has probability exactly 2/32/3, 1/31/3 and 00.
  2. Let L(x′,t)L(x', t) be differentiable in x′x' with ∣∂L/∂x′∣≤B|\partial L / \partial x'| \le B for every tt. Use the dominated convergence theorem to show that ddx′Et[L(x′,t)]=Et[∂L(x′,t)/∂x′]\frac{d}{dx'} E_t[L(x', t)] = E_t[\partial L(x', t) / \partial x'], and show that the mean of mm independent sampled gradients has variance at most B2/mB^2 / m.
  3. Explain why EOT cannot produce an input with the wrong label of a smoothed classifier inside its certified radius, even with an unlimited number of samples.

References

  1. Anish Athalye, Logan Engstrom, Andrew Ilyas and Kevin Kwok, Synthesizing robust adversarial examples, ICML 2018, PMLR 80, pages 284 to 293, the EOT objective with a distance constraint in expectation, the 2D results under noise, distortion and affine transformations, and the 3D printed objects (arXiv:1707.07397)
  2. Anish Athalye, Nicholas Carlini and David Wagner, Obfuscated gradients give a false sense of security, circumventing defenses to adversarial examples, ICML 2018, PMLR 80, pages 274 to 283, EOT as the attack against defenses with random gradients
  3. Nicholas Carlini, Anish Athalye, Nicolas Papernot, Wieland Brendel, Jonas Rauber, Dimitris Tsipras, Ian Goodfellow, Aleksander Madry and Alexey Kurakin, On evaluating adversarial robustness, arXiv 2019, the advice to attack random defenses with EOT and to report the number of samples
  4. Florian Tramer, Nicholas Carlini, Wieland Brendel and Aleksander Madry, On adaptive attacks to adversarial example defenses, NeurIPS 2020, adaptive attacks on random defenses with enough EOT samples

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • five exercises