Part 1 of Adversarial Attacks
What an adversarial example is
Module 1 · 5 min read
What an adversarial example is
TL;DR
- A tiny, computed change to every pixel (FGSM, one gradient-sign step) can flip a correct answer, often to a more confident wrong one.
- Models are close to linear, so many tiny pushes in one direction add up. More pixels means a smaller ε is enough.
- Always ask what the attacker knows, wants and may change (L∞, L2, L0).
The discovery
In late 2013 Christian Szegedy and colleagues posted Intriguing properties of neural networks. They searched for the smallest change that made a state-of-the-art network get a correct image wrong. The changes were invisible to a person and worked on almost every image. What surprised me is that they often fooled a different network too, even one trained on different data. That’s called transferability (module 3). Inputs crafted on purpose to make a model fail are adversarial examples.
The panda that became a gibbon
A year later Ian Goodfellow, Jonathon Shlens and Szegedy published Explaining and Harnessing Adversarial Examples with the picture everyone uses now. A panda at 57.7% confidence, plus a faint pattern scaled to 0.007, becomes “gibbon” at 99.3%. It’s the same panda to us. Random noise that size would mostly cancel out and barely change the answer, so this pattern was computed.
Following the gradient
In training, the gradient tells you which way each weight should move to raise the loss (the error), and you step the other way. An attack keeps the weights fixed, asks the same question for every pixel and nudges each pixel uphill. Goodfellow’s version is the Fast Gradient Sign Method (FGSM).
x_adv = x + ε × sign( gradient of the loss with respect to x )
“Sign” keeps only up or down, so every pixel moves by the same small ε (epsilon). It costs one gradient computation, about one training step, where Szegedy’s method ran a full optimisation per image. That made it cheap enough to use during training, which became the first defence.
Why such a small change is enough
Goodfellow’s answer is that models behave too linearly, and images have a lot of pixels. A linear model’s score is a weighted sum of pixels. Move each pixel by ε along its weight’s sign and the score moves by ε times the sum of the weights’ sizes. A small ImageNet photo (224×224, three colours) has about 150,000 numbers, and 150,000 tiny pushes in one direction make a big one.
This toy model sees a grey “animal” and says cat. Slide ε, then try bigger images with the same ε.
At 8×8 no reasonable ε works because there are only 64 pixels to push with. At 64×64, one or two out of 255 is enough, and real images have far more pixels. So I don’t see this as a bug in one model. It comes from high-dimensional inputs meeting near-linear models, which is why it’s hard to escape.
How big is “small”?
“Small” needs a ruler, and papers mostly use three (norms).
- L∞ (L-infinity) is the biggest change to any one pixel, e.g. “no pixel moves more than 8/255”. The most common.
- L2 is the overall size of the change, like a straight-line distance, so many tiny changes or a few slightly bigger ones.
- L0 counts how many pixels changed at all, e.g. “at most 10 pixels”.
Each ruler allows a different shape around the original. Here it is in two dimensions.
Who is the attacker?
Before judging an attack or a defence, you need a threat model, a clear answer to what the attacker knows, wants and may change.
| Question | Options |
|---|---|
| What does the attacker know? | White-box: everything, including the weights and gradients. Black-box: only the outputs (scores, or just the final label). |
| What do they want? | Untargeted: any wrong answer. Targeted: one specific wrong answer, like “gibbon”. |
| How much may they change? | A budget in one of the norms above, such as L∞ ≤ 8/255. |
| Where does the change happen? | Digital: they edit the pixels directly. Physical: they change the real object, like a sticker, and a camera takes the photo. |
Few attackers have your weights, so why care about white-box attacks? Well, if a defence can’t survive an attacker who knows everything, you have no idea how long it lasts against one who is merely clever.
Quick check
Why can a change of 1/255 per pixel flip a model’s answer on a large image but not on a tiny one?
A roughly linear model sums every pixel’s effect, so many tiny same-direction pushes become a big one (Goodfellow et al.’s linearity explanation).
Q&A
Isn’t this just the model being bad?
No. These models are very accurate on normal test data. Accurate on the test set and robust to small changes are two different things, and a model can have the first without the second.
Does this only happen with images?
No, images are just where it’s easiest to see. It also hits audio (speech that transcribes as a different sentence), text, malware detectors and the language models in module 5.
Papers
- Szegedy et al., Intriguing properties of neural networks (ICLR 2014).
- Goodfellow, Shlens & Szegedy, Explaining and Harnessing Adversarial Examples (ICLR 2015).