Stop 08 · Deep Learning ArchitecturesTopics · 2/11

Pooling Layers

Part of the AI Engineer Roadmap

In short

A CNN produces huge grids of features. Pooling shrinks them while keeping the strongest signals, so the network gets faster and cares less about exactly where something appears.

Downsampling operations (max pooling, average pooling) that reduce spatial dimensions while retaining important features — used between convolutional layers to control model size.

The blob as a teacher collects one raised paper from each small group of desks in a classroom.

Think of it like this

Bench toppers report to the teacher

Instead of reading every student's marks, the teacher asks each bench to send up only its top score. She now has a short list that still shows where the strong students sit. Max pooling sends up the biggest value from each small patch.

Watch it happen

Max pooling with window 2, stride 2

1
0
3
1
2
2
8
3
5
4
4
5
0
6
6
7

1/4One row of feature values from a convolution layer. Big values mean the feature was strongly detected there.

The big ideas

What you need to know

Shrinks the grid

A 2 × 2 pool with stride 2 halves height and width, so the next layers have a quarter of the positions to process.

Small shifts don't matter

If an edge moves by one pixel, the max in that window often stays the same. The network becomes more tolerant of position.

Nothing to learn

Pooling has no weights. It's a fixed rule: take the max, or the average, of each window.

Global average pooling

Many modern CNNs average each whole feature map to one number before the final layer, instead of flattening.

See it in code

Walk through the code

python
1import torch2import torch.nn as nn3 4x = torch.tensor([[[[1., 3., 2., 1.],5                    [4., 6., 5., 0.],6                    [7., 2., 9., 8.],7                    [1., 0., 3., 4.]]]])     # shape (1, 1, 4, 4)8 9print(nn.MaxPool2d(kernel_size=2)(x))   # [[6, 5], [7, 9]]10print(nn.AvgPool2d(kernel_size=2)(x))   # [[3.5, 2.0], [2.5, 6.0]]

1/3One image, one channel, a 4 × 4 grid. PyTorch expects (batch, channels, height, width).

A 4 × 4 feature map becomes 2 × 2. Max pooling keeps the strongest value per corner; average pooling keeps the mean.

Save yourself the pain

Common mistakes

Oops

Pooling so aggressively that a 28 × 28 image is 1 × 1 after three layers.

Do this instead

Track the shape after each layer. Each 2 × 2 pool halves the size, so plan how many you can afford.

Oops

Thinking pooling learns which features matter.

Do this instead

Pooling only summarises. The convolution layers before it do the learning.

Your mission

Pool by hand, then check

~15 min

Quick check

A feature map is 32 × 32. What size is it after nn.MaxPool2d(kernel_size=2)?

Go deeper

  1. 1Add max pooling to a CNN and observe how output dimensions shrink.
  2. 2Learn the difference between max pooling and average pooling.
  3. 3Understand pooling's role in providing translation invariance.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge