Adversarial examples
The $L_\infty$ threat model, the linear nature of the vulnerability, FGSM and PGD, attack transfer and adversarial training as a min–max at a cost in clean accuracy.
Accuracy and robustness
Vision Transformers closed the representations module: CNNs and ViTs that reach high accuracy on held-out images. Every accuracy in the course so far was measured the same way — on test images drawn like the training images. This topic measures something else: accuracy on inputs chosen by someone who wants the network to fail.
A digit MLP can score clean, stay at under random noise, and fall to when the same budget uses attack signs. Size is the same; direction differs. An adversarial example for with label is an with
The allowed set is the threat model. Robust accuracy at budget is the fraction of tests for which no such exists; an attack only upper-bounds it. Standard budgets: on MNIST, on CIFAR-10.
Why even a linear model is vulnerable
Key idea. In high dimension many tiny changes add up. For a linear logit,
attained at . If weights average magnitude , the shift is . A colour image has ; with and the logit moves by about — enough to flip most predictions — from the smallest change an 8-bit file can store.
Networks are built from nearly linear pieces. To first order , so the same construction with maximizes the local linear model. Goodfellow et al. argued models are “too linear, rather than too nonlinear”; on digits one linear step is almost as damaging as twenty careful ones.
FGSM: one step to a corner
The fast gradient sign method (FGSM) takes that maximizer as the attack:
Cost: one forward and one backward pass, in evaluation mode. Every pixel moves by the full , so is a corner of the box.
Worked example: logistic unit , , label , . Logit , probability , loss . Input gradient has sign , so and . The prediction flips. On MNIST, FGSM with made a shallow softmax wrong on of the test set — wrong and confident.
PGD: many steps with projection
FGSM trusts the linear model over the whole box. Projected gradient descent (PGD) trusts it only for small steps. Repeated sign steps of size , each projected back onto the box and the pixel range:
with clipping each coordinate to . Madry et al. start from a random point inside the box. On digits, random noise at costs at most points; FGSM and 20-step PGD drive accuracy near zero by , with PGD only a few points stronger — the network is close to linear inside the box.
Targeted attacks descend the loss of a chosen class (minus sign). Hitting one region is harder than leaving the correct one: at , untargeted PGD already breaks of digit predictions while targeted succeeds on .
Transfer and adversarial training
White-box attacks know the weights. Transfer attacks craft examples on a surrogate and submit them to the target with no queries. They work because models of the same task learn similar functions, so input gradients align. On digits, FGSM from a wider surrogate drops the target to at against white-box. Untargeted examples transfer easily; targeted ones rarely keep their target.
If the network fails on adversarial inputs, train on them. Adversarial training solves
Inner step: PGD for steps to . Outer step: gradient on at , treating as constant. Danskin’s theorem says the chain-rule term through vanishes at a maximizer. Cost about passes per batch. One-step (FGSM) training can catastrophically overfit the one-step direction while staying open to PGD; a random start before FGSM largely prevents that.
The trade-off, and what comes next
On digits, PGD training at raises PGD accuracy from to and drops clean accuracy from to . On CIFAR-10 the clean drop is larger ( → ) and robust accuracy stays far below clean ( under PGD). Tsipras et al. show the trade-off can be unavoidable: non-robust features buy clean accuracy and an adversary can flip them.
A threat model is not the world — rotations, stickers and lighting are other attacks. Accuracy under an attack is only an upper bound; defences that obfuscate gradients can look robust until a stronger attack is used. Certified methods exist but cost more for smaller radii.
Robustness is one deployment budget. The next topic is another: model compression — pruning, distillation, factorization and fewer bits — so a trained net fits memory, latency and energy.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Go deeper — optional
Code and labs do not count toward the main percentage or the certificate.
- FGSM: one step on a logistic unitoptional
Reproduces the topic worked example: gradient sign, ε=0.3, logit sign flip. Self-check in the notebook.
~15 min · easier on a computer · Adversarial examples topic read.
Self-check in the notebook — not part of mastery or the certificate.
Answers are saved on the server and tied to this browser until you sign in.