RECEPTIVE FIELD

Ch 9 ▸ What the network learned ▸ Module 1/4

  1. 1A trained network
  2. 2The first layer
  3. 3The second layer
  4. 4Where it fails

A trained network.

🔒 This module is locked

It builds on Checkerboard artifacts. Pass that module’s knowledge check to unlock it, or skip ahead if you already know the material.

The digits

MNIST is a collection of 70,000 handwritten digits, 0 through 9, each a 28×28 grayscale image with a label saying which digit it is. Every digit was scaled to fit a 20×20 box and then placed in the 28×28 frame so that its ink is centered. It has been a standard first task for CNNs since the 1990s.

The 70,000 are split in two. 60,000 are for training. The other 10,000 are the test set: digits held back from training, used only to measure how well the trained network does. A network can memorize the images it trained on, so a score on those says little. A score on images it never saw says how well it learned digits in general.

The network

The network has five layers. Every one of them comes from an earlier chapter:

  1. A 5×5 convolution with 8 kernels, no padding, then ReLU (chapters 2, 4 and 7). The 28×28 image becomes 8 maps of 24×24, since 28 − 5 + 1 = 24.
  2. A 2×2 max pooling at stride 2 (chapter 5): 8 maps of 12×12.
  3. A 3×3 convolution with 16 kernels, each 3×3×8 because it reads all 8 maps (chapter 4), then ReLU: 16 maps of 10×10, since 12 − 3 + 1 = 10.
  4. Another 2×2 max pooling: 16 maps of 5×5.
  5. A dense layer (chapter 1) that reads all 16 × 5 × 5 = 400 values and gives 10 outputs, one score per digit. The highest score is the network’s guess.

Counting parameters as in chapter 4, each layer is (inputs × outputs) + biases:

That’s 5,386 parameters, and three quarters of them are in the dense layer. Pooling has none.

The training

It was trained exactly the way chapter 7 described. Each digit’s target is 1 for its own score and 0 for the other nine. The loss is the mean squared error between the ten scores and those targets. Each step computes the gradients on a random batch of 64 training digits and moves every weight against its gradient, with step size 1. The network went through all 60,000 training digits 15 times, about 14,000 steps.

On the 10,000 test digits it gets 9,784 right, 97.84%. It gets 216 wrong.

FIG 9.1 ▸ A TRAINED NETWORK DRAW A DIGIT

DRAW HERE

INPUT · 28×28

CONV 1 + RELU · 8 MAPS, 24×24

MAX POOL · 8 MAPS, 12×12

CONV 2 + RELU · 16 MAPS, 10×10

MAX POOL · 16 MAPS, 5×5

DENSE · 10 SCORES

▸ NOTHING DRAWN YET

Test digit
Draw a digit, or load one from MNIST's test set. Your drawing is shrunk to 28×28 and centered the way MNIST's digits were. Maps are black at 0 and white at the largest value in their layer, so a brighter map responded more strongly. The scores come from the dense layer; the highest one is the network's guess.

Draw a digit in figure 9.1, or load one from the test set. Your drawing is prepared the way MNIST’s digits were: shrunk so it fits a 20×20 box and centered in 28×28. The network has only ever seen digits prepared that way.

Follow the digit down the layers. The first layer’s 8 maps still look like the digit, each picking out some of its strokes more brightly than others. One of them, the second, is the other way around: lit everywhere except on the ink. After pooling they’re half the size. The second layer’s 16 maps look less and less like the digit: each lights up in only a few places. By the last pooling, each map is a 5×5 grid of numbers, and the dense layer turns those 400 numbers into ten scores.

The scores show how training aimed them: the right digit’s score near 1, the others near 0. Some digits come out with a clear winner, others with a closer race. The last module comes back to what a close race means.

The rest of the chapter asks what the two convolution layers are responding to.

Knowledge check ▸ 5 questions

Before you move on.

Answer every question correctly to unlock the next module. A wrong answer gets a hint, and you can try again as many times as you like.

  1. 1The first layer runs a 5×5 convolution with no padding at stride 1 on the 28×28 image. How wide is each of its maps?

  2. 2How many parameters does the second convolution have: 16 kernels, each 3×3 over 8 channels, with one bias each?

  3. 3The last pooling leaves 16 maps of 5×5. How many inputs does the dense layer read?

  4. 4During training, what were the ten targets for an image of a 7?

  5. 5Why is the network measured on the 10,000 test digits rather than on its 60,000 training digits?

0 of 5 answered correctly.

🔒 Next module: The first layer