Rowan DasRotman Commerce Résumé

How AlexNet
learned to see

0%

A SUMMARY OF OTHERS’ WORK

PAPER
: ImageNet Classification with Deep CNNs
YEAR
: 2012
AUTHORS
: Krizhevsky, Sutskever, Hinton
FOCUS
: Convolution as vectorized matrix multiplication on GPUs
    01/09Skip »

    ← Previous project: how a machine learns

    Project write-up · NeurIPS 2012

    How AlexNet learned to see

    In 2012 a neural network called AlexNet won an image-recognition contest by a margin nobody expected. Its recipe was not new. What was new was how it was computed: everything turned into vectors and matrices, so a graphics card could do millions of the same small calculation at once.

    Start with step 1

    This is a summary, not original research. It follows the 2012 paper “ImageNet Classification with Deep Convolutional Neural Networks” by Alex Krizhevsky, Ilya Sutskever and Geoffrey Hinton, plus my own study notes. Everything interactive here was built to explain their work.

    An NVIDIA GeForce GTX 580 graphics card with its cooler lifted off, and the GF110 chip lying on the circuit board beside it
    The hardware behind the result: an NVIDIA GTX 580 graphics card with its GF110 chip beside it. AlexNet trained on two of these. Photo: Fritzchens Fritz, Wikimedia Commons, CC0.

    The recipe wasn’t new. What was new was the hardware: one big multiplication that a graphics card can run all at once.

    An elephant standing in a river, the test photo used in the steps below
    The test photo used in steps 1–2. Credits at the bottom of the page.
    60 million
    weights to learn
    650,000
    artificial neurons
    1.2 million
    training images
    5–6 days
    on two GTX 580 GPUs
    15.3%
    top-5 error in 2012, against 26.2% for second place

    On the last page a one-layer model scored a whole digit against one rigid template: W @ x. That is a dot product. This page asks what happens if the templates are small, slide across the picture, and are stacked in layers.

    1Match

    Does This Look Like That?

    The question

    Multiply pairs, add them up. That is a dot product.

    Black and white portrait of Frank Rosenblatt as a young manBlack and white photo of a man at the Mark I Perceptron
    1958 Frank Rosenblatt and the Mark I Perceptron at Cornell. The machine looked at a 20 × 20 grid of 400 photocells and learned a set of weights, a stencil, for telling shapes apart.

    A computer has no eyes. All it has is numbers. So the first question is a tiny one: how do you ask whether a small piece of a picture looks like something you are hunting for?

    Try it below. On the left is a 3 × 3 snapshot. In the middle is a stencil of what you want: green squares mean “I want this bright”, red means “I want this dark”, blank means “I don’t care”. Multiply each square by the stencil and add it all up. It works like a shopping bill: every pixel is a line item, and the total is the match score.

    In one line

    A dot product multiplies matching pairs and adds them up. It is biggest when the snapshot looks like the stencil.

    a · b = a1b1 + a2b2 + … + anbn

    NextThat scores one spot. Next: how do you find where it is in the whole picture?
    2Scan

    Where in the Picture Is It?

    Finding it

    One stencil, checked against every spot in the picture.

    David Hubel speaking into a microphoneTorsten Wiesel smiling, wearing a red scarf
    Diagram of a neuron firing strongly for a line at one angle and weakly for others
    1959–62 David Hubel and Torsten Wiesel recorded from single neurons in a cat’s visual cortex and found cells that fire for a line at one angle in one small part of the view. That is a stencil, found in a brain. They shared the 1981 Nobel Prize in Physiology or Medicine. The recordings below are a diagram of that kind of result, not their original data.

    Step 1 compared one stencil with one small piece of a picture. But a real photo has thousands of pieces. So we do the same check at every spot, one after another, using the same stencil each time.

    Think of the stencil as a set of expectations: “I expect dark on the left and light on the right.” At each spot we ask one question: do the real pixels here meet that expectation? The answer is a match score. Write every score into a grid, in the same position as the spot it came from, and you get a map of where the picture meets your expectation. For an edge stencil, that is a map of where the edges are.

    Below, you play the detective. Choose what you expect to see, then drag the magnifier over the elephant. Or press Scan and let it check everywhere.

    In one line

    One stencil, the same nine numbers, is compared with every spot in the picture. The grid of scores is a feature map: it shows where the picture meets your expectation. Doing this sliding check is called convolution.

    map[i, j] = Σ K[u, v] · X[i + u, j + v]

    NextThat finds one pattern. Next: how do you do it millions of times?
    3Line Up

    How Do You Do That Millions of Times? Line Everything Up.

    Scale

    Line the work up so thousands of workers can do it at once.

    An NVIDIA GTX 580 graphics card with its cooler lifted off
    2010 The GTX 580 has 512 small cores that can all do the same job at the same moment. AlexNet trained on two of them.

    Checking 676 spots for one stencil is already 676 separate sums. AlexNet’s first layer checks 3,025 spots for each of 96 stencils, for every one of over a million photos, over and over. One worker doing one sum at a time would never finish.

    A graphics card is more like a stadium of 512 workers who can all do the same simple job at the same moment. Race them below.

    3ARace the Workers

    3BLine the Work Up

    Grid of handwritten digits from the MNIST dataset
    Same trick Every one of these digits is a 28 × 28 grid. Flatten it and it becomes one row of 784 numbers; stack thousands of rows and you have a table a graphics card can multiply in one go.

    There is a catch: the workers only help if their jobs are identical and lined up. So you rearrange the work first. Cut out every patch, flatten it into a row of numbers, and stack the rows into a table. Now each sum is one row times the stencil, and the whole table is a single multiplication. Making everything a list of numbers (a vector) and a stack of lists (a matrix) is called vectorization.

    3CThe Same Trick for Text

    It is also the idea behind ChatGPT. Words are chunked up, turned into vectors, stacked into a matrix, and operated on again and again (the biggest GPT-3 model repeats the step 96 times). AlexNet puts a label on an image; ChatGPT predicts the next word of a text.

    In one line

    Flatten every patch into a row, stack the rows, and one multiplication does every sum at once. In AlexNet’s first layer that is 3,025 rows, 96 stencils and 363 numbers per row.

    Output (N × M) = P (N × k²C) × K (k²C × M)

    NextNow the work is fast. Next: what does a stencil for a colour photograph look like?
    4Tensors

    What Does a Stencil for a Colour Photo Look Like?

    Shape

    A kernel for a colour picture is a stack: 11 × 11 × 3.

    Real photo One photograph is really three grids: how much red, green and blue is in each pixel. A colour kernel has a layer for each.

    A colour image is three grids stacked: red, green and blue. Height × width × channels. A stack of matrices like that is called a tensor. A kernel for a colour image is a tensor too, and its depth must equal the depth of what it looks at. AlexNet's first layer uses 96 kernels of size 11 × 11 × 3.

    Take the 11 × 11 × 3 chunk of the image under a kernel, multiply each kernel weight by the pixel value beneath it, and add everything up. That is 363 multiplications and one number out. A kernel has 363 numbers it can set freely, its degrees of freedom, and training chooses them. Each kernel is one more way of looking: the more of them, the more the layer can notice.

    4ACount What a Kernel Sees

    4BWhat Do the First-Layer Kernels Look Like?

    Generated A sample of stencils of the kinds the first layer learns: stripes, checkerboards and colour blobs. These are my own generated examples, not the paper’s learned weights.

    The paper shows the 96 kernels its first layer learned. Some are stripes: edge and angle detectors. Some are checkerboards, which respond to fine texture. Some are colourful blobs, which say “green on this side, pink on the other.” The grid below is not the learned weights. I generated kernels in the same three families so you can see what each kind finds in a real photo.

    In one line

    A colour kernel is a stack as deep as its input, and the output size follows from four numbers. AlexNet’s first layer is (227 − 11) / 4 + 1 = 55; the paper says 224, which does not divide evenly.

    ⌊(n + 2p − k) / s⌋ + 1

    NextOne layer is not enough. Next: stack them.
    5Layers

    What Happens After the First Layer?

    Depth

    The output of one layer is the input of the next.

    Portrait of Yann LeCunDiagram of a convolutional network: convolution and pooling layers followed by fully connected layers
    1989–98 Yann LeCun’s team stacked convolution and pooling layers to read handwritten ZIP codes. AlexNet is the same recipe, much bigger. The diagram shows a typical network of this kind.

    After the first layer you are left with 96 maps. They become the input of the next layer, whose kernels take dot products over those maps. The output of each step is the input of the next, so by the end every image has passed through a vast number of multiplications. AlexNet has five convolutional layers, then three fully connected layers that look at everything at once.

    Where do the numbers go? Click a layer. A surprising split appears: almost all of the computation happens in the convolutional layers, but almost all of the weights sit in the fully connected ones.

    In one line

    Each layer’s output is the next layer’s input. Convolution does most of the arithmetic (92%), while the fully connected layers hold most of the weights (96%).

    60,965,224 weights
    724,406,816 multiplications

    NextWhere do all those weights come from? Next: learning.
    6Learning

    How Does It Learn Its Stencils?

    Learning

    Training changes the weights, never the operations.

    David Rumelhart at a conferencePortrait of Geoffrey Hinton
    1986 David Rumelhart and Geoffrey Hinton, with Ronald Williams, showed that the error can be passed backwards through a network to tell every weight which way to move. That is the update rule you just played with.

    The operations inside AlexNet never change: dot products, a rectifier, pooling. Training changes only the weights those operations use. Backpropagation works out, for every single weight, which direction to nudge it so the answer is a little less wrong, by passing the error backwards through the layers.

    On the last page the nudge was a flat plus or minus the picture. Here it is the slope of the error: w ← w − ε · ∂L/∂w. Below, a tiny network starts with random kernels and has to learn to tell vertical lines from horizontal ones. Nobody tells it what an edge detector looks like.

    6AWatch a Kernel Learn

    6BThe Paper’s Update Rule

    AlexNet used a slightly richer version of that nudge. It keeps a running momentum so steps build speed in a consistent direction, and a little weight decay that pulls weights gently towards zero. The authors found the decay was not just a regulariser: it lowered the training error. Change the three knobs and watch a weight roll down a valley.

    6CLearning, Seen in Weight Space

    There is a picture that makes training click. Forget the image for a moment and treat the weights themselves as a point. A kernel with three weights is one point in 3D space; AlexNet is one point in a space with 60 million directions. Each training example puts a flat wall through the origin: weights on one side get it right, weights on the other get it wrong. Where every example’s right-hand side overlaps is a cone of feasible solutions. Training is just moving the point until it is inside the cone. Geoffrey Hinton draws exactly this picture when he teaches the perceptron.

    In one line

    Training never changes the operations, only the weights. Each weight is nudged against its slope, with momentum and a pinch of weight decay.

    v ← 0.9v − 0.0005εw − ε·∂L/∂w
    w ← w + v

    NextThat is the idea. Next: the paper’s own choices, section by section.
    7The Paper

    What Did the Paper Actually Do?

    The paper

    Every section of the paper, in plain English.

    The authors credit their result to a short list of choices, which they sort by importance in Section 3. Here is the paper in plain English, one section at a time. Each one has something to try.

    Portrait of Geoffrey Hinton
    Geoffrey Hinton
    Supervisor
    Ilya Sutskever seated on a stage
    Ilya Sutskever
    Co-author

    The paper’s three authors were all at the University of Toronto. The first author, Alex Krizhevsky, wrote the GPU code that made the training fast enough; I couldn’t find a freely licensed photo of him. Photos: Cmichel67 and Eladkarmel, Wikimedia Commons, CC BY-SA 4.0.

    In one line

    The paper credits a short list of choices: ReLU neurons, two GPUs, normalisation and overlapping pooling, then augmentation and dropout against overfitting.

    top-5 error
    26.2% → 15.3%

    NextSo what did all that produce? Next: the 4,096 numbers.
    8Embeddings

    What Does the Network End up With?

    Meaning

    Distance in a learned space follows content, not pixels.

    An African forest elephant mother and calf drinkingAn elephant walking away across the savanna
    A tusker elephant standing in the open
    Same animal Different poses, light and backgrounds: far apart as raw pixels, but close together in the network’s 4,096-number space. That is what the paper’s nearest-neighbour test shows.

    Every image the network sees is mapped through those levels of multiplications into a long list of numbers. Stop one layer early and grab it: a vector with 4,096 numbers. A vector is a point in 4,096-dimensional space. Just as you can measure the distance between two points on a map, you can measure it in that space.

    The authors did exactly that. They took a test image’s vector, found the training images whose vectors were closest, and the nearest images were, for example, all elephants. Yet they note that at the pixel level those pictures are generally not close, because the elephants appear in a variety of poses. This is an embedding space: distance and direction mean something about the content, not just the colours.

    8AElephants in Pixel Space

    8BA Small Embedding You Can Explore

    I can’t run AlexNet itself in a web page, but the digit model from the last page is a very small embedding. Its ten learned templates are ten directions, and a digit’s score for each is how far it lies along that direction. Pick two directions and every digit becomes a point on a map.

    8CPicking the Closest One

    Now the last step. When a new picture comes in, the network turns it into its vector, which is a single point. Every picture it has seen before is already a point in the same space. To recognise the new one, find the points nearest to it and let them vote. If most of the closest points are elephants, it is probably an elephant.

    In one line

    Compare two images by the distance between their 4,096-number vectors, not their pixels. Close in that space means similar in content.

    d(a, b) = √( Σ (ai − bi)² )

    NextAnd why did this happen in 2012? Next: the history and the hardware.
    9Why 2012

    Why Did This Happen in 2012?

    Timing

    An old idea, waiting for new hardware.

    Geoffrey Hinton and John Hopfield side by side on a stage at Nobel Prize week
    2024 Geoffrey Hinton and John Hopfield at Nobel Prize week. The 2024 Physics prize recognised their foundational work on artificial neural networks.

    Almost none of AlexNet's ingredients were new. Convolutional networks that learn their kernels were already reading ZIP codes in 1989. Backpropagation was published in 1986. What blocked a network this large was hardware and data: there were too few labelled images and not enough computing power to train something so big. The authors were explicit that their results should improve simply by waiting for faster GPUs and bigger datasets.

    9AThe Ingredients

    1979–80

    Neocognitron

    Kunihiko Fukushima builds a layered network of small, repeated feature detectors that inspired convolutional networks.

    David Rumelhart at a conference

    1986

    Backpropagation

    Rumelhart, Hinton and Williams show how to train many layers of weights by passing the error backwards.

    Portrait of Yann LeCun

    1989–98

    LeNet

    Yann LeCun’s team trains convolutional networks that read handwritten ZIP codes and bank checks.

    Fei-Fei Li speaking at a conference

    2009

    ImageNet

    Fei-Fei Li’s team presents a database of millions of labelled photographs, a thousand times bigger than earlier sets.

    An NVIDIA GTX 580 graphics card

    2010

    GPUs for General Computing

    The GTX 580 arrives in November with 512 cores and a programming system that lets researchers use it for maths, not only games.

    Portrait of Geoffrey Hinton

    2012

    AlexNet

    All of it combined, on two GTX 580s, wins the ImageNet contest by a wide margin.

    9BThe Arithmetic

    In one line

    The recipe was decades old. Big data and GPUs supplied the missing arithmetic: by my estimate about 200,000 times LeNet-5’s training operations, done in about five days.

    about 4.7 × 1017
    operations to train

    What to Take Away

    1. A dot product measures similarity. A kernel is a template, and the dot product says how well a patch matches it.
    2. Convolution reuses a few weights everywhere. That makes the model small, and it finds patterns wherever they are.
    3. Vectorization makes it fast. Unroll patches into rows, stack them into a matrix, and one multiplication does thousands of dot products at once.
    4. Training changes weights, never operations. Backpropagation says which way to nudge each one.
    5. The idea was old; the computing was new. Big data plus GPUs turned a known algorithm into a breakthrough.

    Looking Inside

    Once a network like this is trained, people try to read it. One approach, the activation atlas (Carter and colleagues, 2019), lays out what thousands of neurons respond to in a single map. A more recent one extracted millions of interpretable features from a production language model (Anthropic, “Scaling Monosemanticity”, 2024). Both rest on the idea you just played with: the weights are learned, and what they have learned can be measured.

    Sources and Credits

    Paper: Krizhevsky, A., Sutskever, I. and Hinton, G. E. (2012), ImageNet Classification with Deep Convolutional Neural Networks, NeurIPS (NIPS) 25. All architecture, training and results figures are from this paper. Layer sizes and operation counts are my own arithmetic from the architecture it describes. Everything else is explanation of other people’s work, from my own study notes, with context from Wikipedia’s articles on AlexNet, LeNet, ImageNet and the GeForce 500 series.

    Elephant and landscape photos (Wikimedia Commons): bathing elephant and river elephant by Basile Morin (CC BY-SA 4.0); walking away and savanna elephant by Daniel Case (CC BY-SA 4.0); mother and calf by JosepMGracia (CC BY-SA 4.0); tusker by Yathin S Krishnappa (CC BY-SA 3.0); trees on the savanna by Cosal (CC BY-SA 4.0); upland savanna by Gossipguy (CC BY-SA 3.0). Photos are scaled down for the page and otherwise unaltered.

    People: Fei-Fei Li by ITU Pictures (CC BY 2.0); Ilya Sutskever by Eladkarmel (CC BY-SA 4.0); Hinton, LeCun and Rumelhart as credited on The godfathers of AI.

    History photos (Wikimedia Commons unless noted): David Hubel by Joey cantod (CC BY-SA 4.0); Torsten Wiesel by Suawikicommons (CC BY-SA 4.0); neuron recordings diagram by Jimmierock (CC BY-SA 3.0); convolutional network diagram by Aphex34 (CC BY-SA 4.0); MNIST digits by Josef Steppan (CC BY-SA 4.0). Rosenblatt, the Mark I Perceptron, Rumelhart, LeCun and Hinton as credited on The godfathers of AI. Fei-Fei Li and Ilya Sutskever as listed above.

    Not the paper’s own figures. The kernel grid, the learning demo and the embedding map are my own illustrations. They show the ideas; they are not AlexNet’s learned weights or outputs.