Pooling summarises each small window of a feature map by its maximum or average, shrinking the map, adding a little tolerance to small shifts, and having no parameters. Global average or max pooling collapses each whole map to one number, which makes the features position-invariant and replaced the large fully connected heads of early CNNs. This page covers max and average pooling, their gradients, global pooling, and what pooling does and does not buy. In the exercises you implement pooling and its gradient and show its shift invariance is only local, then classify shapes placed anywhere in an image using random convolution filters and a linear readout: unpooled features gave 30% accuracy, 2 × 2 pooling 33%, global average 71% and global max 84%.
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.
Summarise each neighbourhood
After a convolution has marked where a pattern appears, pooling summarises small neighbourhoods: max pooling keeps the strongest response in each 2 × 2 patch, average pooling keeps the mean. The map shrinks, the next layer sees a wider area, and a pattern that moves by a pixel within a patch gives the same result. Global pooling goes all the way: one number per feature map, answering “is this pattern anywhere in the image?”
CNN building blocks
input 9 × 9
→
output 8 × 8
output size ⌊(9 − 2)/1⌋ + 1 = 8 · no parameters to learn
Deep-learning "convolution" slides a small learned kernel over the input (no flip). Stride shrinks the output, padding preserves borders, dilation spreads the kernel to see further without more weights. Pooling summarises windows. Stacking layers grows the receptive field. Depthwise-separable and grouped convolutions cut cost by not connecting every input channel to every output channel. Transposed convolution upsamples, but uneven kernel overlap leaves checkerboard patterns. Squeeze-and-excitation rescales whole channels by gates computed from their global averages; CBAM adds a per-pixel spatial gate. (Here the gates are fixed functions of the averages so you can see their effect; in a network the excitation is learned.)
Why engineers care
Pooling and global pooling control the size and cost of a network and make classifiers work wherever the object appears. Global average pooling replaced the huge fully connected heads of early CNNs, cutting millions of parameters, and lets one network accept images of any size.
📝 Quick check (Level 0)
0/3 answered
1. Max pooling keeps…
2. Pooling layers have…
3. Global pooling gives one number per…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.
Output size: ⌊(n − k)/s⌋ + 1: 224 → 112 for k = s = 2; 7 → 3 for k = 3, s = 2.
Gradients: max pooling sends each output’s gradient to the position of its maximum (others get 0); average pooling spreads it equally, for example 4 → (1, 1, 1, 1) over a 2 × 2 window.
Global average pooling of channels [[0, 1], [2, 3]] and [[4, 5], [6, 7]] gives (1.5, 5.5).
Head size: a linear classifier on 512 × 7 × 7 flattened features for 1000 classes has 25 089 000 parameters; after global pooling, 513 000.
📝 Quick check (Level 1)
0/3 answered
1. Max-pool 2 × 2 of [[0, 1], [4, 5]]:
2. Output size for n = 7, k = 3, s = 2:
3. Head parameters after global pooling (512 → 1000):
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.
Pooling in code
Exercise 1.
Pooling a 4 × 4 ramp gave [[5, 7], [13, 15]] (max) and [[2.5, 4.5], [10.5, 12.5]] (average).
The max-pooling gradient matched finite differences, with exactly one non-zero entry per window.
An impulse moving within a window (column 0 to 1) left the pooled output unchanged; moving across a window boundary (1 to 2) changed it.
Practice.
Modern backbones often downsample with strided convolutions instead of max pooling, keep one early max pool, and end with global average pooling.
nn.AdaptiveAvgPool2d(1) gives global pooling for any input size.
For detection and segmentation, keep spatial resolution (pooling discards position).
head = torch.nn.Sequential(torch.nn.AdaptiveAvgPool2d(1), torch.nn.Flatten(), torch.nn.Linear(512, num_classes))
🐍 Exercise 1: pooling and its gradient
Implement max and average pooling and the max-pooling gradient, check the gradient by finite differences, and test pooling's shift invariance.
📝 Quick check (Level 2)
0/3 answered
1. Modern CNNs often downsample with…
2. Global pooling for any input size in PyTorch:
3. A shift across a window boundary…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.
Theory
Invariance. Max pooling over a window is invariant to any rearrangement within that window, giving local translation invariance. Stacked pooling layers increase it, but each also subsamples, which breaks exact equivariance (E7-1).
Max versus average. For detecting whether a feature is present, the maximum is the natural statistic: averaging dilutes a strong local response by the empty area around it. Boureau, Ponce and LeCun (2010) analysed when each is better; max pooling suits sparse, rare features.
Global average pooling. Lin, Chen and Yan (2014) replaced fully connected heads by global average pooling, which enforces a correspondence between feature maps and categories and removes most head parameters. It also enables class activation maps: the classifier’s weights applied to the maps show where in the image the evidence is.
Without pooling. Springenberg et al. (2015) showed strided convolutions can replace pooling with no loss; the “all-convolutional” design is common today.
📝 Quick check (Level 3)
0/3 answered
1. Max pooling suits features that are…
2. Global average pooling enables…
3. The all-convolutional net replaced pooling with…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.
Which pooling helps a classifier find shapes anywhere?
History.
K. Fukushima (1980) used pooling-like “C cells” in the neocognitron.
M. Riesenhuber and T. Poggio (1999) argued for max pooling in models of vision.
M. Lin, Q. Chen and S. Yan (2014) introduced global average pooling; B. Zhou et al. (2016) class activation maps.
J. Springenberg et al. (2015) proposed the all-convolutional net.
Exercise 2. Four shape classes placed anywhere on 16 × 16 noisy images. Features: 16 fixed random 3 × 3 filters with ReLU, then pooling; a ridge readout trained on 100 images, tested on 2000. Three seeds:
pooling
features
test accuracy
none
3136
0.295
max 2 × 2
784
0.326
average 2 × 2
784
0.326
global max
16
0.836
global average
16
0.706
Without pooling the readout barely beat chance (0.25): with shapes anywhere, 100 examples are too few to learn a position-specific template for each location.
2 × 2 pooling helped little: it tolerates only one-pixel moves.
Global pooling, with just 16 position-invariant numbers, reached 71–84%; global max was best because each shape produces a strong response somewhere, which averaging dilutes.
🐍 Exercise 2 (research): which pooling helps a classifier find shapes anywhere?
Compare no pooling, 2 × 2 pooling and global max and average pooling on random convolutional features for shapes placed anywhere.
Pooling in AI, robotics and aerospace
Scene classification from onboard cameras uses global pooling so the answer does not depend on where objects appear.
Variable-size inputs: global pooling lets one network handle different camera resolutions.
Explainability: class activation maps from globally pooled networks show operators where the evidence for a detection lies.
References
M. Lin, Q. Chen, S. Yan (2014). “Network in network.” Proc. ICLR.
Y.-L. Boureau, J. Ponce, Y. LeCun (2010). “A theoretical analysis of feature pooling in visual recognition.” Proc. ICML.
J. T. Springenberg, A. Dosovitskiy, T. Brox, M. Riedmiller (2015). “Striving for simplicity: the all convolutional net.” ICLR Workshop.
B. Zhou, A. Khosla, A. Lapedriza, A. Oliva, A. Torralba (2016). “Learning deep features for discriminative localization.” Proc. CVPR.
Global pooling made random features usable for shapes anywhere; global max beat global average.
Practice
Show:
Level 0
Problem 1Level 0
Max-pool of [[0, 1], [4, 5]]?
5.
Problem 2Level 0
Average-pool of [[0, 1], [4, 5]]?
2.5.
Problem 3Level 0
Output size of 2 × 2, stride-2 pooling on 224?
112.
Level 1
Problem 4Level 1
Output size for n = 7, k = 3, s = 2?
3.
Problem 5Level 1
Global average of the channel [[4, 5], [6, 7]]?
5.5.
Problem 6Level 1
Head parameters after global pooling, 512 channels, 1000 classes?
513 000.
Problem 7Level 1
Gradient per cell when 4 is spread by 2 × 2 average pooling?
1.
Level 2
Problem 8Level 2
Head parameters on flattened 512 × 7 × 7 features, 1000 classes?
25 088 × 1000 + 1000 = 25 089 000.
Problem 9Level 2
Global max accuracy in exercise 2?
0.836.
Problem 10Level 2
Global average accuracy?
0.706.
Problem 11Level 2
No-pooling accuracy?
0.295.
Problem 12Level 2
Unpooled features: 16 maps of 14 × 14?
3136.
Problem 13Level 2
Non-zero gradient entries for 2 × 2 max pooling of a 6 × 6 map?
One per window: 9.
Level 3
Problem 14Level 3
Derive the gradient of max pooling.
Each output yᵢⱼ equals x at the window’s arg max m. Locally (with a unique maximum), yᵢⱼ = x_m, so ∂yᵢⱼ/∂x_m = 1 and ∂yᵢⱼ/∂x_other = 0. By the chain rule the input gradient is gᵢⱼ at m and 0 elsewhere, summed if windows overlap. ∎
Problem 15Level 3
Explain why global max beat global average in exercise 2.
Each image contains one small shape on a large noisy background. A filter tuned to part of the shape responds strongly at a few positions and weakly elsewhere. The maximum captures that strong response regardless of the background area, while the average divides it by the 196 positions and mixes in noise responses, so the class signal is weaker relative to noise. ∎
Problem 16Level 3
Explain why the unpooled readout failed with 100 images.
With 3136 position-specific features, the readout must learn a separate template for each place a shape can appear. With shapes anywhere on the image and only 100 examples, most positions were never seen with each class, so the readout could not generalise to new positions; it was close to chance (0.25). Pooling builds position invariance in, so the readout only has to learn which filters respond to which class. ∎
Problem 17Level 3
Advise a head for a classifier that must accept images from cameras with different resolutions.
Use a fully convolutional backbone followed by global average (or attention) pooling and a small linear head; the pooled vector has a fixed size whatever the input size. Train with multi-scale inputs so features are calibrated across resolutions, and verify accuracy at each camera’s resolution. If location matters, keep a spatial head instead. ∎
Level 4
Problem 18Level 4
Max 2 × 2 accuracy in exercise 2?
0.326.
Problem 19Level 4
Features after 2 × 2 pooling?
16 × 7 × 7 = 784.
Problem 20Level 4
Advantage of global max over global average?
0.836 − 0.706 = 0.13.
Coding practice
🐍 Code 1 (Level 0): 2 × 2 max pooling
Non-overlapping 2 × 2 maximum.
🐍 Code 2 (Level 0): global average pooling
(C, H, W) → (C,).
🐍 Code 3 (Level 0): output size
⌊(n − k)/s⌋ + 1.
🐍 Code 4 (Level 1): head parameters
Flattened versus globally pooled features.
🐍 Code 5 (Level 1): average-pool gradient
Spread each gradient over its k × k window.
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
Pooling: Max, Average and Global Average: topic test
10 questions, drawn at random from a bank of 21. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.