Foundations to Frontier
Tests
E. Deep Learning › E7 CNN Building Blocks

Pooling: Max, Average and Global Average

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%.

Level 0: Foundation

★☆☆☆☆ 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. 1. Max pooling keeps…
  2. 2. Pooling layers have…
  3. 3. Global pooling gives one number per…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Max pooling 2 × 2, stride 2 on [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]] → [[5, 7], [13, 15]]; average pooling → [[2.5, 4.5], [10.5, 12.5]].
  • 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. 1. Max-pool 2 × 2 of [[0, 1], [4, 5]]:
  2. 2. Output size for n = 7, k = 3, s = 2:
  3. 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. 1. Modern CNNs often downsample with…
  2. 2. Global pooling for any input size in PyTorch:
  3. 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. 1. Max pooling suits features that are…
  2. 2. Global average pooling enables…
  3. 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

  1. M. Lin, Q. Chen, S. Yan (2014). “Network in network.” Proc. ICLR.
  2. Y.-L. Boureau, J. Ponce, Y. LeCun (2010). “A theoretical analysis of feature pooling in visual recognition.” Proc. ICML.
  3. J. T. Springenberg, A. Dosovitskiy, T. Brox, M. Riedmiller (2015). “Striving for simplicity: the all convolutional net.” ICLR Workshop.
  4. B. Zhou, A. Khosla, A. Lapedriza, A. Oliva, A. Torralba (2016). “Learning deep features for discriminative localization.” Proc. CVPR.