TL;DR
Max pooling takes a grid of numbers (a Matrix), cuts it into small non-overlapping windows, and keeps the largest value in each window. The result is a smaller grid that records where the strongest responses were, without caring about their exact position inside the window. It has no weights to learn.
Where you'll see it: between the convolution blocks of image classifiers such as early convolutional networks, where it halves the width and height of each feature map after every stage.
Intuition
Imagine a grid of numbers that says how strongly each small patch of an image matched a pattern, say a vertical edge. A high number means "the edge is here". For many questions a network asks, the exact pixel where the edge sits does not matter. What matters is that an edge exists somewhere in this region.
Max pooling answers that question directly. Take each small region, keep the strongest signal, and throw away the rest. The grid gets smaller, so later layers do less work, and each remaining value now covers a wider piece of the image. Because the output is the maximum, moving the feature slightly inside the window leaves the output unchanged. That gives the network a little tolerance to small shifts, which is useful when the same object can appear a few pixels to the left or right.
The pipeline usually looks like this:
flowchart LR A["Input image"] --> B["Convolution (feature detection)"] B --> C["Nonlinearity (ReLU)"] C --> D["Max pooling (downsample)"] D --> E["Next convolution layer"]
Convolution finds patterns, and pooling compresses the map of where those patterns are strongest.
The math
Setup
Let be an input grid of height and width , with entries . Choose a window size (the side of a square window) and a stride (how far the window moves between placements). Pooling produces an output with entries
For each output position , the window covers the input entries with offsets and running from to . The output takes the largest of those values.
The output height and width follow from how many full windows fit:
The symbol means rounding down to a whole number. With and (the usual setting), windows do not overlap and each dimension is halved when it is even.
Common settings
When the windows tile the grid with no overlap. When they overlap. AlexNet used overlapping windows of size 3 with stride 2. Padding can be added around the input to control the output size, but most pooling layers use no padding.
Gradient through the max
Pooling has no weights, but it is still part of the computation that Backpropagation must differentiate. Let be the loss and let be the gradient arriving at an output. Only one input in each window influences its output: the one that was the maximum. Call that position for the window. Then
The gradient is copied to the winning position and zero is sent to the others. Ties are handled by choosing one winner, which is a convention rather than something the math decides. When windows overlap (), one input can win in several windows, and its gradient is the sum of the gradients from all of them.
Worked examples
Take the input with window and stride :
- Output size: , so the output is .
- Top-left window holds . Maximum is .
- Top-right window holds . Maximum is .
- Bottom-left window holds . Maximum is .
- Bottom-right window holds . Maximum is .
- Result: . The grid of 16 numbers became 4 numbers, and the largest value in the image (9) survived.
Use a one-dimensional input with window and stride . The forward pass gives windows , , and outputs .
Suppose the loss gradients arriving at the outputs are .
- Window one: the maximum is at position 1 (counting from 1). It receives gradient . Position 2 receives .
- Window two: the maximum is at position 3. It receives gradient . Position 4 receives .
- Window three: the maximum is at position 6. It receives gradient . Position 5 receives .
- Input gradient: .
- Interpretation: only the winning entries affect the loss, so only they are updated. The value at position 2 changed nothing in the output, so nudging it would change nothing either. This is why max pooling is cheap in both directions.
Tradeoffs and failure modes
Max pooling is simple, fast and parameter-free. Its main cost is that it discards information: every value in a window except the largest is ignored, including how many strong responses there were. Its tolerance to shifts is also only local, because a shift that moves the peak into a neighbouring window still changes the output.
| Situation | Problem | Better choice |
|---|---|---|
| Need the average strength of a region | Max keeps only the peak | Average pooling |
| Output must keep the input size (segmentation, generation) | Pooling shrinks the grid | Fewer or no pooling layers (padded convolutions keep size), or restore size later with upsampling or transposed convolution |
| Fine spatial detail matters (small objects) | Repeated pooling blurs it away | Fewer pooling layers, or dilated convolution |
| Want learned downsampling | Max has nothing to tune | Strided convolution with learned weights |
| Want invariance to global position | Local windows keep position information | Global average or global max pooling over the whole map |
A common failure is stacking too many pooling layers on a small input. Each halving removes spatial resolution, and after a few steps a image has only a few cells left to describe it. On ordering: the usual sequence is convolution, then activation, then pooling. For a non-decreasing activation such as ReLU, taking the max and applying the activation commute, so pooling first gives the same result with fewer activations to compute. For activations that are not monotone the order changes the answer.
History
Pooling in neural networks grew out of earlier work on local averaging. Fukushima's Neocognitron (1980) used layers that combined nearby responses to build tolerance to position. LeCun and colleagues' convolutional networks of the late 1980s and 1990s used subsampling layers to shrink feature maps; the LeNet paper of 1998 is the standard reference for that design. The Riesenhuber and Poggio HMAX model of visual cortex (1999) argued that taking a maximum over a neighbourhood matched how some visual neurons respond, which helped motivate max pooling. It became standard after the 2012 AlexNet paper, which used overlapping max pooling in a large convolutional network trained on GPUs and won the ImageNet competition by a wide margin.
Check yourself
QuestionA input is pooled with window and stride . What is the output size?Show answer
. The output is , which is 9 numbers from 36. Windows do not overlap, and each one covers a block.
QuestionFor the window , which value does max pooling output, and which input entries receive zero gradient on the backward pass?Show answer
The output is . Only the entry receives the incoming gradient; the entries , and receive zero gradient because a small change to them would not change the maximum.
QuestionWhy does max pooling give some tolerance to shifts of the input, and when does that tolerance break down?Show answer
If a feature moves by a pixel but stays inside the same window, the maximum is unchanged, so the output is unchanged. The tolerance breaks down when the peak moves across a window boundary; then the window containing it changes, and the output changes. It is also only local, so large shifts still matter.
QuestionA 3 by 3 window with stride 1 is applied to a grid. Compute the output size and say whether the windows overlap.Show answer
, so the output is . The windows overlap heavily, since each window shares two columns and two rows with its neighbours.
QuestionA network needs its output to be the same size as its input for per-pixel labels. Why is max pooling a poor choice for that layer, and what would you use instead?Show answer
Pooling shrinks the grid, so the output no longer lines up with the input pixels. A transposed convolution (or plain upsampling) can restore resolution, or the network can use dilated convolutions to keep resolution while enlarging the receptive field. Max pooling is fine inside an encoder, but the decoder must put resolution back.
Sources
- Pooling layer (Wikipedia): https://en.wikipedia.org/wiki/Pooling_layer
- LeCun, Bottou, Bengio, Haffner, Gradient-based learning applied to document recognition (1998): https://ieeexplore.ieee.org/document/726791
- Krizhevsky, Sutskever, Hinton, ImageNet classification with deep convolutional neural networks (2012): https://papers.nips.cc/paper/2012/hash/c399862d3b9d6b76c8436e924a68c45b-Abstract.html