Downsampling with no parameters
- : the window of the input that this output position summarises.
Max pooling takes the largest value in each window and discards the rest. A 2 by 2 window with stride 2 quarters the number of positions.
Average pooling takes the mean instead. Neither has a single weight to learn, which is why pooling layers are invisible in a parameter count and very visible in a memory profile.
The output size follows the same rule as a convolution with no padding, and the usual halves each spatial dimension.
What the gradient does
Max pooling routes the entire gradient to the one input that won, and gives nothing to the others.
Average pooling splits it evenly across the window.
So the forward pass needs the values and the backward pass needs the indices of the winners, which is the one thing a pooling layer has to remember.
What it buys
Each pooling layer doubles the reach of everything above it, so a small kernel in a late layer covers a large part of the original image.
It also quarters the work of every layer that follows, which is most of why a deep image network is affordable at all.
Small translations of the input often leave the maximum of a window unchanged, so the representation is slightly invariant to where a feature sits.
What it costs
Five halvings take an image to a 7 by 7 grid, and everything finer than 32 pixels of the original has been thrown away.
That is fatal for segmentation and detection, which need to say where something is to the pixel. It is why U-Net keeps skip connections and why detectors read from several depths at once.
Modern architectures increasingly replace pooling with a strided convolution, which downsamples with learned weights instead of a fixed rule, at the cost of parameters and arithmetic.
The one that replaced the flatten
Global average pooling collapses each channel to a single number, turning a feature map into a vector the classifier can read.
The alternative, flattening a 7 by 7 by 512 map into a dense layer, costs 25 million parameters and ties the network to one input size.
Global pooling costs none, accepts any input size, and generalises better, which is why every architecture after 2015 uses it.