Max pooling summarizes each local window by taking its single largest value โ the most widely used pooling variant, on the intuition that the strongest activation of a detected pattern within a region is usually the most important signal to preserve.
Formula
Numerical Example
A 4ร4 feature map: \(\begin{bmatrix}1&3&2&4\\5&6&1&2\\3&2&8&1\\1&4&2&3\end{bmatrix}\), max pooled with a 2ร2 window, stride 2:
Why "Max" Rather Than Some Other Summary
A high value in a feature map indicates strong evidence that the filter's pattern was detected at that position โ taking the maximum within a region preserves exactly this "was the pattern detected anywhere in this region, and how strongly" signal, discarding the (often less important) exact positional and weaker-activation details. This makes max pooling particularly well suited to feature-detection-style tasks like image classification, where "did this pattern appear somewhere nearby" often matters more than precisely where.
Code
import torch
import torch.nn as nn
x = torch.tensor([[[[1.,3.,2.,4.],
[5.,6.,1.,2.],
[3.,2.,8.,1.],
[1.,4.,2.,3.]]]]) # shape (1,1,4,4)
max_pool = nn.MaxPool2d(kernel_size=2, stride=2)
print(max_pool(x))
# tensor([[[[6., 4.],
# [4., 8.]]]]) -- matches the manual calculation
Common Mistakes
- Assuming max pooling is always strictly better than average pooling โ it discards a lot of information (only the single largest value survives per window), which isn't always ideal, particularly for tasks where the overall magnitude or distribution of activations across a region matters, not just its peak.
- Forgetting max pooling has no learnable parameters โ as with pooling in general (see Pooling), it's a fixed operation.
Interview Relevance
Q: "Why is max pooling commonly used in image classification CNNs?" It preserves the strongest signal of a detected pattern within each local region, discarding less-relevant weaker activations and exact positional detail โ matching the intuition that for recognizing whether an object or feature is present, "was this pattern strongly detected somewhere nearby" usually matters more than its precise sub-position, and this summary is cheap to compute with zero added parameters.
Practice Question
Apply 2ร2 max pooling (stride 2) to the feature map \(\begin{bmatrix}2&1&5&3\\4&0&2&6\end{bmatrix}\).