RoboticsUnit 2 · Deep learning explosion · Day 08

ImageNet Classification with Deep Convolutional Neural Networks (AlexNet)

A big convolutional network, a big labelled dataset and two gaming GPUs beat years of hand-engineered vision features by a wide margin. Deep learning took over computer vision from here.

AuthorsAlex Krizhevsky, Ilya Sutskever, Geoffrey E. Hinton
Year / venue2012 · NIPS (now NeurIPS)
Core ideaDeep CNN + GPUs + lots of data
Study time3–5 h

Original: NeurIPS proceedings · Code, notebook and exercises: 30u30 Day 8

Start here (no maths needed)

In 2012, a big computer program that learned from over a million labelled photos beat every hand-built method at naming what was in a picture, and it beat them by a lot.

Think of it like this

Think about how you learned to tell dogs from cats. Nobody gave you a rule book about ear shapes. You just saw lots and lots of dogs and cats. AlexNet learns the same way. It looks at over a million photos, each with a label like "dog" or "car", until it can name things in photos it has never seen.

How it works

  1. The program looks at a photo through many small "windows", each one checking a small patch for simple things like edges and colours.
  2. The next layers combine those simple things into bigger ones: textures, then shapes, then parts like eyes or wheels.
  3. The last layers put it all together and give a score for each of 1,000 possible labels.
  4. If the top answer is wrong, the program nudges its settings a tiny bit so it does better next time.
  5. Two graphics cards (the chips used for video games) did this millions of times over about a week.

Why robots care

Before a robot can pick up a cup, it has to find the cup in its camera picture. Programs like AlexNet made robots much better at recognising objects. Robots today still use the same trick: start with a program trained on millions of everyday photos, then teach it a little more with pictures of the robot's own objects.

Try it

Words to know

Neural network
A computer program that learns from examples instead of being given rules.
Convolution
Sliding a small window over a picture and checking each spot for a pattern.
GPU
A graphics chip that can do lots of simple maths at the same time.
Parameters
The numbers inside the program that change as it learns.
Overfitting
Memorising the training photos instead of learning ideas that work on new photos.

Going deeper: everything below is the full version, with some maths. On a first read, skim the headings and the "Why it matters for robotics" box, and come back for the rest later.

1. Summary

TL;DR

The authors trained a CNN with five convolutional and three fully-connected layers on the 1.2 million labelled images of the ImageNet challenge. It had 60 million parameters and took five to six days on two GTX 580 GPUs. In the ILSVRC-2012 competition it scored a 15.3% top-5 error. The second-best entry, built on hand-designed features, scored 26.2%. Almost none of the parts were new. What was new was putting them together at this scale, plus a few practical tricks that made training fast enough and stopped the network from overfitting.

2. The core idea

A convolutional layer slides a small set of learned filters over the image. Each filter is reused at every position, so the layer has far fewer weights than a fully-connected one:

out[k, y, x] = ReLU( b_k + Σ_c Σ_i Σ_j  W[k, c, i, j] · in[c, y·s + i, x·s + j] )
ReLU(z)      = max(0, z)

The full network stacks these: conv1 → pool → conv2 → pool → conv3 → conv4 → conv5 → pool → fc6 (4096) → fc7 (4096) → fc8 (1000-way softmax). Training uses SGD with batch size 128, momentum 0.9 and weight decay 0.0005. The learning rate starts at 0.01 and is divided by 10 whenever validation error stops improving. That happened three times over about 90 epochs.

The paper also uses local response normalisation (each activation is divided by a term that grows with the activity of neighbouring channels at the same position) and overlapping max pooling (3×3 windows with stride 2). Each gave a small gain: LRN cut top-1/top-5 error by 1.4%/1.2%, overlapping pooling by 0.4%/0.3%. Later networks dropped LRN in favour of batch normalisation.

3. Deep dive

Why it worked in 2012 and not in 2005

CNNs were not new. LeCun's networks read handwritten digits in the 1990s. Three things changed at once:

The authors expected this trend to continue, saying "our results can be improved simply by waiting for faster GPUs and bigger datasets". That bet is the seed of the scaling story in Day 25. Splitting the model across two GPUs is an early ancestor of the model parallelism in Day 24.

Overfitting control at 60 million parameters

Each label carries only about 10 bits of information. With 1.2 million images that's not enough to pin down 60 million weights, so the paper fights overfitting on two fronts:

Where the parameters and the compute live

Interactive: AlexNet layer budget

Per-layer parameters versus multiply-adds for one image. Sizes follow standard reimplementations: 55×55 after conv1 (the arithmetic needs a 227-pixel input, though the paper says 224), with conv2, conv4 and conv5 seeing only their own GPU's half of the channels.

Total
–
Share in conv
–
Share in FC
–

The pattern is lopsided. About 96% of the weights sit in the three fully-connected layers, fc6 alone holding about 38 million. About 92% of the arithmetic happens in the convolutions. Later architectures (GoogLeNet, ResNet on Day 09) replaced the big FC layers with global average pooling and cut parameters sharply. For a robot, compute is usually the tighter limit, and that sits in the conv layers. Day 28 walks through the same bookkeeping for VGG.

Limitations, and what came after

4. Why it matters for robotics

5. How to study it

  1. Read the paper (9 pages, about 1.5 h). Focus on Sections 3 and 4. Sections 3.1–3.4 are ordered by how much each trick mattered.
  2. In the 30u30 Day 8 folder, read implementation.py and match each layer to Figure 2 of the paper. Then run train_minimal.py on the small dataset it uses.
  3. Work through notebook.ipynb, then the exercises: building the network, an ablation study, feature visualisation, transfer learning and modern replacements such as batch norm.
  4. Do the ablation honestly: swap ReLU for tanh, remove dropout, remove augmentation. Plot training curves and compare with the paper's claims.
  5. Stretch: for each conv layer, compute output size, parameters and multiply-adds by hand, then check against the demo above. The TensorTonic conv problems from Module 02 are good practice.

6. Self-check

Why do ReLUs train faster than tanh units?

tanh saturates. For large positive or negative inputs its gradient is close to zero, so learning slows down. ReLU has gradient 1 for every positive input. The paper measured about six times faster training on CIFAR-10.

Most parameters are in the FC layers. Why does most compute happen in the conv layers?

A conv filter is small but runs at every spatial position. conv1 has only about 35k weights, yet it applies them at 55×55 positions. An FC weight is used once per image.

Name the two main ways AlexNet fought overfitting.

Data augmentation (random crops, flips and PCA colour shifts) and dropout in the first two fully-connected layers.

What does test-time averaging over ten crops buy you, and what does it cost?

A small accuracy gain: 37.5% versus 39.0% top-1 on ILSVRC-2010. The cost is ten forward passes per image, which a real-time robot usually can't afford.

What is top-5 error?

The fraction of test images whose correct label is not among the model's five most probable guesses.

7. Further reading