3.4.6 · D4Convolutional Neural Networks

Exercises — LeNet and AlexNet

2,537 words12 min readBack to topic

This is a self-testing page. Each problem sits above a collapsible solution. Try it first, then open the box. Problems climb from L1 Recognition (just recall the fact) to L5 Mastery (combine everything). Every symbol is defined the first time it appears.

Parent topic: LeNet and AlexNet. Related building blocks you may want open in another tab: Convolutional Layers, Pooling Layers, Activation Functions, Backpropagation, Dropout, Batch Normalization.

The figure below turns that story into a picture. A tiny input strip of width (the cyan cells) is scanned by a window taking stride : follow the coloured boxes labelled "hop 0", "hop 1", … — each arrow points up to the input cells that box covers, and each box produces exactly one output value. Count the boxes and you have counted the outputs: . That count is the formula.

Figure — LeNet and AlexNet

Level 1 — Recognition

Exercise 1.1

LeNet-5 and AlexNet each end with a layer of a specific size that equals the number of classes they predict. State the output-layer size for each network, and say which dataset forces that number.

Recall Solution
  • LeNet-5: final layer has neurons, one per digit . The dataset is MNIST (handwritten digits). See Image Classification.
  • AlexNet: final layer has neurons, one per class in the ImageNet Dataset (1000 categories). The rule to remember: the last layer's width = number of classes, because each neuron there answers "how much does the picture look like this class?"

Exercise 1.2

Which activation did LeNet use, and which did AlexNet use? Write each function's rule.

Recall Solution
  • LeNet used (the hyperbolic tangent), a smooth S-shaped curve squashing every input into the range .
  • AlexNet used ReLU (Rectified Linear Unit): — "keep positives, flatten negatives to zero." See Activation Functions.

Exercise 1.3

LeNet used average pooling; AlexNet used max pooling. In one sentence each, describe what these two operations do to a block of numbers.

Recall Solution
  • Average pooling: replace the four numbers with their arithmetic mean (add them, divide by 4).
  • Max pooling: replace the four numbers with the single largest of the four. See Pooling Layers.

Level 2 — Application

Exercise 2.1

LeNet's first conv layer C1: input , kernel , padding , stride . Compute the output side length . Show each substitution.

Recall Solution

Plug into with : So C1 outputs per filter. With 6 filters the full tensor is .

Exercise 2.2

LeNet S2 average-pooling: input , window , stride , padding . Compute .

Recall Solution

Pooling uses the same formula with (the pool window plays the role of the kernel): Output — exactly what the parent note lists.

Exercise 2.3

AlexNet's real Conv1 uses effective input , kernel , padding , stride . Show that the output is , and explain where the floor actually bites.

Recall Solution

Here divides evenly, so the floor changes nothing. If you (wrongly) use : , floor to , giving — that's where the floor does bite, and why the "224" figure is a paper-side simplification.

The figure contrasts these two inputs side by side: the amber bar is the case that floors down to , the cyan bar is the correct case that lands exactly on . Notice the amber bar is shorter — that missing pixel is precisely what the floor threw away, and it is why practitioners quietly pad the input to .

Figure — LeNet and AlexNet

Level 3 — Analysis

Exercise 3.1

A convolutional layer's parameter count (weights only, ignore biases) is where is the number of input channels and is the number of filters. Each filter must look at all input channels at once, hence the factor. Compute the weight count of AlexNet Conv1 (, RGB, ).

Recall Solution

Why ? The input is RGB, so every filter is itself a little cube; it sees red, green, and blue simultaneously and produces one output map. See Convolutional Layers.

Exercise 3.2

Compare the gradient of and ReLU at a strongly-activated positive input, say . Explain in one line why this comparison predicts AlexNet trains faster.

Recall Solution
  • gradient: . At , , so gradient — essentially zero (the "vanishing gradient").
  • ReLU gradient at any is exactly . During Backpropagation gradients are multiplied layer-by-layer. A per-layer factor of shrinks the signal catastrophically over many layers; a factor of passes it through untouched. That is the mechanical reason for the empirical 6× faster convergence.

Exercise 3.3

Dropout with drop-probability zeroes each neuron independently. At test time we multiply every activation by . Show algebraically why is the correct scale, using expectation.

Recall Solution

Let denote the neuron's output activation — the single number this neuron would pass forward if it were never dropped. Let the random mask be with probability (kept) and with probability (dropped). During training the neuron passes . Its expected output is At test time no neuron is dropped, so the raw output is — a factor too large compared to what the next layer saw during training. Multiplying by restores the training-time expected scale. See Dropout.


Level 4 — Synthesis

Exercise 4.1

Trace AlexNet's spatial size through its first stack: Conv1 (?) then MaxPool1 (, stride , padding ). Give both output side lengths.

Recall Solution

Conv1 (from Ex 2.3): . MaxPool1 on , , , : So , matching the parent note's .

Exercise 4.2

AlexNet Conv2 keeps spatial size fixed at using padding. Given kernel , stride , what padding achieves "same" output ()? Solve for .

Recall Solution

With stride the division is exact, so drop the floor and solve: Padding — precisely the value in the AlexNet spec. General rule: for stride 1 and an odd kernel side , "same" padding is , which for gives . ✓ See VGGNet, which builds entire networks from such same-padded layers.

Exercise 4.3

LeNet has parameters; AlexNet has . Express AlexNet's parameter count as a multiple of LeNet's, and state which single component of AlexNet dominates that count.

Recall Solution

Ratio . AlexNet is 1000× larger. The dominant chunk is the first fully-connected layer FC6: it connects the flattened features to neurons, i.e. million weights — well over half of all parameters. This is exactly why Dropout was applied to the FC layers: they hold the most parameters and overfit most easily.


Level 5 — Mastery

Exercise 5.1

Build a mini "same-padded" stack and prove size preservation. You feed a input through three consecutive Conv layers, each , stride , padding . What is the final side length, and why does depth cost nothing spatially here?

Recall Solution

For one layer: . Carefully: , then . Size unchanged. Because each layer preserves size, three stacked layers give . Spatial cost is zero; only the receptive field grows (each layer widens what an output pixel "sees" by , so three layers see a region). This is the core insight behind VGGNet and later ResNet: stack cheap same-padded convs to gain depth without shrinking the map.

Exercise 5.2

Full LeNet spatial trace as a self-check. Starting from , apply C1 (, s1, p0), S2 ( pool, s2), C3 (, s1, p0), S4 ( pool, s2), C5 (, s1, p0). List all five output sizes and confirm C5 collapses to .

Recall Solution
  • C1: .
  • S2: .
  • C3: .
  • S4: .
  • C5: . C5 outputs — a kernel on a map has exactly one placement, so it acts like a fully-connected layer. ✓ This is why the parent note calls C5 "effectively FC".

The figure below is your visual answer key: five shrinking cyan squares, each labelled with its side length, marching left to right from down to the single cell. Watch the square shrink at every arrow — conv layers nibble the border away (no padding), pooling halves it, until nothing spatial is left and C5 behaves like a dense layer.

Figure — LeNet and AlexNet

Exercise 5.3

Design decision under a budget. Suppose you must downsample a input to roughly in a single conv layer, using a kernel and padding . What stride achieves this? Verify.

Recall Solution

We want . Solve . So . Try : . ✓ Output . Stride works. (This is essentially ResNet's stem: a big-kernel, big-stride first layer for cheap aggressive downsampling — see ResNet.)


Recall Rapid self-quiz (cloze)

The output-size formula is ::: AlexNet's real Conv1 uses effective input side ::: "Same" padding for a stride-1 kernel of odd side is ::: ReLU's gradient for is exactly ::: Dropout test-time scale factor is ::: AlexNet is this many times larger than LeNet in parameters :::