By Antwi

Here is a panda.
It’s a young giant panda in a tree. It has dark patches around its eyes, black ears and a bit of branch in the lower left corner. If you were asked what it was, you’d say “a panda” and wonder why I was asking.
In 2014, some Google researchers (Goodfellow, Shlens and Szegedy, 2015) showed this image to GoogLeNet, one of the best image recognition programs of the time. Unsurprisingly, it also said panda, though only with 57.7% confidence.
Now imagine a second picture that, to a human eye, is identical to the first. GoogLeNet identifies it as a gibbon, a kind of small ape with long arms, with 99.3% certainty.
The second picture is simply the first picture with a small calculated noise vector added to it:

The middle image looks like random static, but it has been calculated extremely precisely. Every value in the photo has been nudged up or down by , about the smallest change an ordinary image file can store.
Pictures engineered like this are called adversarial examples, a name given by the researchers who first described them (Szegedy et al., 2014). According to Goodfellow, Shlens and Szegedy (2015), the reason they work has very little to do with software glitches and almost everything to do with how geometry behaves when space has many thousands of dimensions.
A Picture is a Point
The panda photo is pixels wide by pixels high. Each pixel is represented by three colour numbers: red, green and blue. The entire photo is a list of:
We can represent this list as a vector (a list of numbers treated as a single object, like coordinates of a point) where . In other words, the photo is a single point in a -dimensional space, and every other possible photo of this size is another point in the same space.
Since it would be hard to imagine dimensions, let’s use a simplified model: an image with just two pixels. Each two-pixel picture is a point in a two-dimensional plane.
Let’s say we’re trying to classify these two-pixel images as pandas and gibbons. The simplest classifier draws a straight line on the plane:
Given a weight vector and threshold , we calculate the score , the dot product: multiply matching entries and add them up, so . Points on one side of the line are pandas and points on the other side are gibbons.

In higher dimensions the straight line becomes a hyperplane, but the mathematical rule remains identical:
A program that sorts inputs this way is called a linear classifier. During training, the computer adjusts the weight vector using millions of labelled images, until the decision boundary separates the classes correctly.
The Optimisation Problem
Suppose you are an attacker who can change each coordinate of an image by at most . What is the largest amount you can change the classification score by?
Consider a perturbation vector (the Greek letter eta: the list of changes we make to each pixel) and a new image , with the constraint for every pixel . Using the linearity of the dot product:
So the only change in the score is .
It helps to try a small example by hand first. Take an image with four pixels and a classifier with these weights:
The score is
Say anything below counts as a panda, so this is a panda. Now we may move each pixel by at most , and we want to push the score up as far as possible. The first weight is positive, so making bigger raises the score: we add . The second weight is negative, so making smaller raises the score: we subtract . Doing the same for all four pixels gives
and the score goes up by
The new score is . Still a panda, and barely any different, but notice the trick: every pixel pushed the score the same way.
In general, to maximise this change, we consider each dimension independently:
Adding up the shift over all dimensions, the maximum possible shift is:
So the best push is to move every pixel by the full , in the direction its weight points:
where means replacing each weight with if it is positive and if it is negative. The sum of the sizes of the weights, ignoring signs, is called the 1-norm, written . This is exactly what we did in the example, where and the score rose by .

How Far is the Boundary?
The change in score grows with , since there is one term for every pixel. But scores alone can mislead: doubling every weight and leaves the line where it is, yet doubles every score. What actually matters is the distance from the image to the boundary.
The shortest distance from an image to the boundary is:
The top is how far the score is from the threshold. The bottom, written , is the length of , found by Pythagoras. Dividing by it undoes the scaling problem: double the weights and , and the top and bottom both double, so stays the same.
Using our optimal perturbation , the distance we move towards the boundary is:
In the four-pixel example, the top is and the bottom is , so . The push moved the picture about towards the line, but it started away. No wonder it was still a panda.
The amplification ratio decides how much a very small pixel change is magnified in high-dimensional space. is always between and . It is biggest when all the weights are the same size: if every , the top is and the bottom is , so . For a standard image (), the maximum magnification factor is:
There is also a geometric reason why appears. The constraint means the new image has to stay inside a box centred on : a square in two dimensions (the grey square in Figure 3), a cube in three, and an -dimensional hypercube in general. The faces of the box are always from the centre, but its corners are
away. The perturbation always points towards one of these corners. So although a change of in each pixel is not perceptible to humans, to the neural network, which takes all dimensions into account at once, the image point has travelled a large distance through the space.
Beyond Linear Approximations
Many of the key building blocks of deep neural networks are piecewise linear functions, such as the ReLU, . Designers use them because they make networks much easier to train (Goodfellow, Shlens and Szegedy, 2015).
Close to the input image , a curved decision boundary can be treated as if it were flat. The idea is the same as a tangent line: if you zoom in far enough on a smooth curve, it looks like a straight line, so for a small step, new value old value slope step. With many variables it works the same way, except there is one slope for each pixel: how fast the score changes if you nudge that pixel alone and leave the rest. The list of all these slopes is a vector called the gradient, written . So for a small change to the whole image:
So the best adversarial perturbation is:
Compare this with the linear classifier: the gradient is playing exactly the role the weights played before. This is known as the Fast Gradient Sign Method (FGSM), introduced in the same paper. In some sense, the same properties that make deep networks easy to train are what make them vulnerable to perturbations in high dimensions.
Conclusion
So the panda becomes a gibbon not because of a software glitch, but because of geometry. A change of in each pixel is far too small for us to see, but a classifier adds up all of them, and the image travels a long way through the space the classifier works in. This isn’t just a trick on a screen either: a 3D-printed turtle with a specially designed pattern on its shell can fool a computer vision system into seeing a rifle (Athalye et al., 2018).
As AI models are used in important areas such as self-driving cars, medical diagnosis and security, it becomes increasingly important to understand the geometry of high-dimensional space.
Acknowledgements. Thanks to ChatGPT for drawing the diagrams, since my LaTeX skills aren’t quite there yet. I asked it whether they were all correct, and it said it was 99.3% sure.
Cover photo: Giant panda by Jeff Kubina, public domain, via Wikimedia Commons.





Leave a Reply