The pooling lecture introduced downsampling in general. Max pooling is its most common form and the historical default in CNNs. It keeps only the strongest response in each window—ideal for detecting whether a feature is present. The next lecture contrasts it with average pooling.
Learning Objectives
By the end of this lesson, students should be able to:
- Define max pooling and compute its output by hand.
- Explain why keeping the maximum suits feature-presence detection.
- Describe how gradients flow through max pooling during backprop.
- Apply
nn.MaxPool2dwith correct window and stride settings. - Identify artifacts max pooling can introduce (loss of location detail).
- Choose max pooling versus average pooling appropriately.
Max pooling slides a window over each feature map and outputs the maximum value in each window, discarding the rest.
Worked Example
A 2×2 max pool with stride 2 on a 4×4 map takes the max of each non-overlapping 2×2 block:
Why the Maximum?
A high activation means the filter’s pattern is strongly present somewhere in the window. Max pooling keeps that evidence and ignores exactly where it occurred within the window—the source of its shift-robustness. For tasks like “is there an edge here?” the strongest response is the most informative summary.
Gradients Through Max Pooling
Max pooling has no parameters, but it still participates in backpropagation. During the forward pass it records which input position was the maximum; on the backward pass the gradient flows only to that position, and all other positions in the window receive zero. This is a sparse, routing-style gradient.
Max Pooling in PyTorch
Max vs. Average at a Glance
| Property | Max Pooling | Average Pooling |
|---|---|---|
| Keeps | Strongest activation | Mean activation |
| Good for | Sharp feature presence | Smooth/background context |
| Sensitivity to outliers | High (picks the peak) | Low (averages them out) |
| Typical use | Hidden layers | Global pool before head |
Strengths and Tradeoffs
Strengths
- Preserves the most salient features.
- Strong shift-robustness.
- Parameter-free and fast.
Tradeoffs
- Discards sub-window location detail.
- Ignores non-maximal activations entirely.
- Can be too aggressive for dense prediction (segmentation).
“Max pooling averages the window.” That is average pooling. Max pooling takes only the single largest value—so a lone strong activation dominates its neighbors entirely.
Knowledge Check
- Short Answer: What does max pooling output per window? Answer: The maximum value in that window.
- True/False: Max pooling has learnable parameters. Answer: False.
- Multiple Choice: 2×2 stride-2 max pool on max(3,7,1,5) window outputs: (a) 4, (b) 7, (c) 16. Answer: (b).
- Short Answer: During backprop, where does the gradient flow in a max-pool window? Answer: Only to the position that held the maximum.
- True/False: Max pooling is generally more sensitive to outliers than average pooling. Answer: True.
- Multiple Choice: Max pooling is best when you care about: (a) average brightness, (b) whether a feature is present, (c) channel count. Answer: (b).
- Short Answer: What does
return_indices=Trueprovide? Answer: The positions of the maxima, useful for unpooling. - Short Answer: Does max pooling change channel count? Answer: No—only spatial dimensions.
- True/False: Max pooling preserves exact within-window location. Answer: False—it discards it.
- Multiple Choice: Max pooling contributes to: (a) more parameters, (b) translation invariance, (c) larger channels. Answer: (b).
Key Takeaways
- Max pooling keeps the strongest activation in each window.
- It excels at detecting feature presence and adds shift-robustness.
- Gradients route only to the max position; it has no parameters.
- It discards non-max detail—too aggressive for some dense tasks.
- Next, Average Pooling covers the smoothing alternative.
Hands-on idea: Have students hand-compute a 2×2 max pool on a 4×4 grid, then verify with nn.MaxPool2d.
Discussion prompt: Why does routing gradients to only the max position make sense during training?
Recap: Max pooling summarizes each window by its peak, preserving salient features cheaply. Continue with Average Pooling.