← Master Index
Vol. 07 Module 7.1 Lecture

Max Pooling

CNN Core Concepts

How This Lesson Fits the Module

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.MaxPool2d with correct window and stride settings.
  • Identify artifacts max pooling can introduce (loss of location detail).
  • Choose max pooling versus average pooling appropriately.
Definition

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:

Input (4x4) 2x2 windows -> max 1 3 | 2 4 max(1,3,5,6)=6 max(2,4,7,8)=8 5 6 | 7 8 ------+------ Output (2x2) 9 2 | 1 0 max(9,2,4,3)=9 max(1,0,2,1)=2 4 3 | 2 1 [6 8] [9 2]

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

import torch from torch import nn x = torch.tensor([[[[1.,3,2,4], [5,6,7,8], [9,2,1,0], [4,3,2,1]]]]) # shape (1,1,4,4) pool = nn.MaxPool2d(kernel_size=2, stride=2) print(pool(x)) # tensor([[[[6., 8.], # [9., 2.]]]]) # return_indices lets you recover argmax positions (used by unpooling) pool_idx = nn.MaxPool2d(2, 2, return_indices=True) out, idx = pool_idx(x) print(idx) # locations of the maxima

Max vs. Average at a Glance

PropertyMax PoolingAverage Pooling
KeepsStrongest activationMean activation
Good forSharp feature presenceSmooth/background context
Sensitivity to outliersHigh (picks the peak)Low (averages them out)
Typical useHidden layersGlobal 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).
Common Misconception

“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

  1. Short Answer: What does max pooling output per window? Answer: The maximum value in that window.
  2. True/False: Max pooling has learnable parameters. Answer: False.
  3. Multiple Choice: 2×2 stride-2 max pool on max(3,7,1,5) window outputs: (a) 4, (b) 7, (c) 16. Answer: (b).
  4. Short Answer: During backprop, where does the gradient flow in a max-pool window? Answer: Only to the position that held the maximum.
  5. True/False: Max pooling is generally more sensitive to outliers than average pooling. Answer: True.
  6. Multiple Choice: Max pooling is best when you care about: (a) average brightness, (b) whether a feature is present, (c) channel count. Answer: (b).
  7. Short Answer: What does return_indices=True provide? Answer: The positions of the maxima, useful for unpooling.
  8. Short Answer: Does max pooling change channel count? Answer: No—only spatial dimensions.
  9. True/False: Max pooling preserves exact within-window location. Answer: False—it discards it.
  10. 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.
Trainer’s Guide

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.