Privacy note: We capture your IP address to provide customised and focused services. See our Privacy Policy.

Deep Learning & Neural Networks — Alpha School

Lesson 11: Pooling, Padding and Modern CNN Design

The last lesson introduced the CNN as a stack of convolutions and pooling. This lesson looks closer at the design choices inside that stack, because they decide whether a network trains well or wastes its capacity. Three ideas matter most: padding, which controls how the edges are treated; pooling, which controls how fast the maps shrink; and depth, which controls how complex the features can become.

Padding adds a border of zeros around the input before a convolution. Without it, every convolution shrinks the map, and the pixels at the edges are used by fewer filter positions than the pixels in the middle — the edges are effectively under-examined. With padding of one pixel, a 3 by 3 filter keeps the map the same size, and edge pixels get a fair share of attention. Most modern networks use padding of one with 3 by 3 filters, so the map size only changes when pooling is applied deliberately.

How Deep Should a Network Be?

Deeper networks can learn more complex features, but depth has costs. Each layer adds weights to train and time to run, and very deep networks can suffer from vanishing gradients, where the learning signal fades before it reaches the early layers. A key design answer is the residual connection: a shortcut that adds a layer's input to its output, so the signal has a direct path through. Networks with such shortcuts can be dozens or even hundreds of layers deep and still train well.

Another modern pattern is to use many small filters instead of a few large ones. Two 3 by 3 convolutions stacked together see the same region as one 5 by 5 filter, but they use fewer weights and add an extra activation function in between — an extra bend, which adds representational power. This is why modern CNNs are built almost entirely from small 3 by 3 convolutions: the pattern is simple, cheap, and effective.

Putting the Design Together

A typical modern CNN follows a clear rhythm: a block of two or three convolutional layers with padding, then a pooling layer that halves the map; repeat, with more filters each time as the maps get smaller; then flatten and classify. The number of filters grows — 32, then 64, then 128 — because as the maps shrink, each position must carry more kinds of information. Starting from this template and changing one thing at a time is a far better strategy than inventing an architecture from scratch.

When your own CNN underperforms, check these design points before anything exotic: is the padding right, is the pooling halving the maps as expected, is the network deep enough to build the features the task needs, and is the data augmented? Most CNN failures are ordinary failures — a wrong size, an unscaled input, too little data — and the design template above makes them easy to spot.

Counting the Cost of a Network

Every design choice in a CNN has a cost measured in computation and memory, and it is worth learning to estimate it roughly. A convolutional layer's cost grows with the size of the feature map, the number of input filters, the number of output filters, and the size of the filter itself. Doubling the number of filters roughly quadruples the work of that layer, because each new filter must be applied to every input map. This is why the early layers, where the maps are large, use few filters, and the later layers, where the maps are small, can afford many. The architecture is a budget, and the designer spends it where it buys the most understanding.

The same thinking applies to the size of the model you save and share. A network with millions of weights needs tens of megabytes of storage, which matters on a phone or a small device, and which is why smaller models are often preferred even when a larger one scores slightly better. A good engineer asks not only how accurate a model is, but how much it costs to run, store and maintain. The best model for a task is rarely the biggest one; it is the smallest one that meets the requirement.

Key Terms

Padding
A border of zeros added around an input so a convolution does not shrink it or neglect the edges.
Residual connection
A shortcut that adds a layer's input to its output, helping gradients flow through deep networks.
Receptive field
The region of the original image that one neuron's value depends on.
Downsampling
Reducing the size of a feature map, usually by pooling or by a larger stride.
Filter count
How many filters a convolutional layer learns; later layers usually use more.
Architecture
The design of a network: which layers it has, in what order, and how big they are.

Discussion Questions

  1. Without padding, why do edge pixels get less attention from a convolution than middle pixels?
  2. A residual connection gives the gradient a shortcut. Why does that help very deep networks train?
  3. Two 3 by 3 convolutions see the same area as one 5 by 5 filter. Why might the pair be better?

Practice Questions

  1. What does padding of one pixel do for a 3 by 3 convolution?
  2. A feature map is 32 by 32. After 2 by 2 max pooling, how big is it?
  3. What problem do residual connections solve?
  4. Why do later convolutional layers usually have more filters than earlier ones?
  5. Why are many small 3 by 3 filters preferred over a few large ones?
Show answers
  1. It keeps the output the same size as the input, and gives edge pixels a fair share of filter positions. Without padding the map would shrink by 2 in each direction.
  2. 16 by 16. Pooling halves each dimension.
  3. The vanishing gradient in very deep networks. The shortcut gives the learning signal a direct path through the layers.
  4. Because the maps are smaller, so each position must carry more kinds of information. The filter count typically grows — 32, 64, 128 — as the maps shrink.
  5. Two 3 by 3 layers see the same region as one 5 by 5 filter but use fewer weights and add an extra activation function between them. That extra bend adds power cheaply.
Keep reading to complete this lesson