Pooling
Pooling is a technique used in CNNs to reduce the size of feature maps while keeping the most important information. It makes the network smaller, faster, and less sensitive to small changes in an image.
What Is Pooling?
After convolution, a CNN produces feature maps. These feature maps can be large.
Pooling takes small regions of the feature map and summarizes them into fewer values.
Feature Map
↓
Pooling
↓
Smaller Feature Map
So the simplest definition is:
Pooling = Reduce the size of a feature map
while keeping important information.
Why Do We Need Pooling?
Feature maps can contain a large number of values. Processing all of them through every layer can be expensive.
Pooling reduces the amount of information that needs to be processed.
Large Feature Map
↓
Pooling
↓
Small Feature Map
↓
Less computation
Pooling can also make the network less sensitive to small changes in the exact location of a feature.
Max Pooling
Max pooling selects the largest value from each region.
For example, suppose we have this feature map:
Feature Map
1 3 2 4
5 6 1 2
7 2 8 3
4 1 5 6
We use a 2 × 2 max-pooling window.
First region:
1 3
5 6
The largest value is:
max(1, 3, 5, 6) = 6
Move the window to the next region:
2 4
1 2
The largest value is:
max(2, 4, 1, 2) = 4
Doing this for the entire feature map gives:
Original:
1 3 2 4
5 6 1 2
7 2 8 3
4 1 5 6
After 2 × 2 Max Pooling:
6 4
7 8
Max Pooling Step by Step
Let's look at the calculation clearly.
Input:
1 3 2 4
5 6 1 2
7 2 8 3
4 1 5 6
Take the first 2 × 2 region:
1 3
5 6
Maximum = 6
Take the second region:
2 4
1 2
Maximum = 4
Bottom-left region:
7 2
4 1
Maximum = 7
Bottom-right region:
8 3
5 6
Maximum = 8
Therefore:
6 4
7 8
Why Does Max Pooling Keep the Maximum?
A high value in a feature map usually means that the corresponding filter detected its feature strongly.
Feature Map Region
1 2
3 9
9 = strongest response
Max Pooling
↓
9
Max pooling therefore keeps the strongest detected response from each region.
Filter detects a feature
↓
Feature map contains responses
↓
Max pooling keeps strongest response
Average Pooling
Another type of pooling is average pooling.
Instead of selecting the largest value, average pooling calculates the average of the values in the region.
Region:
2 4
6 8
Calculate the average:
(2 + 4 + 6 + 8) / 4
= 20 / 4
= 5
Therefore:
Max Pooling:
→ 8
Average Pooling:
→ 5
Max Pooling vs Average Pooling
Region:
2 4
6 8
Max Pooling
↓
8
Average Pooling
↓
5
Max pooling keeps the strongest activation. Average pooling keeps the average activation.
In many practical CNN architectures, max pooling is more commonly used for feature extraction, although modern architectures do not always use pooling layers.
Pool Size
The pool size determines how large the pooling window is.
A common choice is:
pool_size = (2, 2)
This means the pooling operation looks at a 2 × 2 region at a time.
┌───────┐
│ 2 × 2 │
└───────┘
↓
One output value
Pooling Stride
Stride tells the pooling window how far it moves after each calculation.
For example:
pool_size = 2 × 2
stride = 2
The window moves two positions at a time.
Step 1
[■ ■] ■ ■
[■ ■] ■ ■
■ ■ ■ ■
■ ■ ■ ■
Step 2
■ ■ [■ ■]
■ ■ [■ ■]
■ ■ ■ ■
■ ■ ■ ■
A stride of 2 is commonly used with a 2 × 2 pooling window to reduce the spatial dimensions by roughly half.
How Pooling Reduces Size
Suppose we have a 4 × 4 feature map:
4 × 4
1 3 2 4
5 6 1 2
7 2 8 3
4 1 5 6
Apply 2 × 2 max pooling with stride 2.
Before:
4 × 4
After:
2 × 2
6 4
7 8
The spatial size has been reduced from 16 values to 4 values.
Pooling Keeps Important Information
Pooling does not simply throw away values randomly. Max pooling keeps the strongest response in each region.
Region:
0.1 0.2
0.3 0.9
↓
Max Pooling
↓
0.9
If 0.9 represents a strong feature detection, that important response is preserved.
Pooling and Small Changes in Position
Pooling can make a CNN less sensitive to small changes in the exact position of a feature.
Imagine an edge moves slightly inside the same pooling region.
Before:
1 2
3 9
Max = 9
Feature moves slightly:
2 1
9 3
Max = 9
The exact location changed, but the strongest response remains 9.
This is one reason pooling can provide some degree of translation robustness.
Max Pooling With Python
We can implement simple max pooling using NumPy.
import numpy as np
feature_map = np.array([
[1, 3, 2, 4],
[5, 6, 1, 2],
[7, 2, 8, 3],
[4, 1, 5, 6]
])
pooled = np.zeros((2, 2))
for i in range(2):
for j in range(2):
region = feature_map[
i * 2:i * 2 + 2,
j * 2:j * 2 + 2
]
pooled[i, j] = np.max(region)
print("Pooled Feature Map:")
print(pooled)
Output:
Pooled Feature Map:
[[6. 4.]
[7. 8.]]
Understand the Python Code
First, we create the feature map.
feature_map = np.array([
[1, 3, 2, 4],
[5, 6, 1, 2],
[7, 2, 8, 3],
[4, 1, 5, 6]
])
Then we create a 2 × 2 output matrix.
pooled = np.zeros((2, 2))
The loops visit each 2 × 2 region.
for i in range(2):
for j in range(2):
This extracts the current region.
region = feature_map[
i * 2:i * 2 + 2,
j * 2:j * 2 + 2
]
Then we select the largest value.
pooled[i, j] = np.max(region)
Finally, the maximum values form the smaller feature map.
Original Feature Map
↓
Take 2 × 2 region
↓
Find maximum
↓
Store maximum
↓
Repeat
↓
Smaller Feature Map
Pooling With Keras
In a real CNN, we normally use Keras to perform pooling.
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(
filters=32,
kernel_size=(3, 3),
activation='relu',
input_shape=(128, 128, 3)
),
tf.keras.layers.MaxPooling2D(
pool_size=(2, 2)
)
])
The important line is:
tf.keras.layers.MaxPooling2D(
pool_size=(2, 2)
)
This tells Keras to apply 2 × 2 max pooling.
Input
128 × 128
↓
Convolution
↓
Feature Map
128 × 128
↓
2 × 2 Max Pooling
↓
Feature Map
64 × 64
Where Does Pooling Fit in a CNN?
Input Image
↓
Convolution
↓
Activation
↓
Feature Map
↓
Pooling
↓
Smaller Feature Map
↓
Convolution
↓
Activation
↓
Pooling
↓
Smaller Feature Map
↓
Fully Connected Layer
↓
Prediction
Pooling is therefore usually applied after convolution and activation in traditional CNN designs.
Does Every CNN Use Pooling?
No. This is an important point.
Pooling is common in CNNs, but modern architectures can reduce spatial dimensions using strided convolutions or other techniques instead.
Traditional approach:
Convolution
↓
Pooling
Another approach:
Strided Convolution
↓
Spatial reduction
So do not memorize "every CNN must have pooling." The important concept is that CNNs often need some mechanism to reduce spatial dimensions.
The Big Picture
Input Image
↓
Convolution
↓
Feature Map
↓
Pooling
↓
Smaller Feature Map
↓
Less computation
↓
Next CNN Layer
↓
More complex features
↓
Prediction
Think of pooling as a way of saying:
"I don't need every single value.
Keep the important information
and make the representation smaller."
Easy Way to Remember
MAX POOLING
Look at a small region
↓
Find the largest value
↓
Keep it
↓
Move to the next region
The most important formula to remember is:
Max Pooling
= Keep the strongest value
Average Pooling
= Calculate the average value
Check Your Understanding
What is pooling?
Pooling reduces the spatial size of a feature map
while keeping useful information.
What does max pooling do?
It selects the largest value from each pooling
region.
What does average pooling do?
It calculates the average value of each pooling
region.
Why is pooling useful?
It reduces computation and can make the network less
sensitive to small changes in feature location.
What does a 2 × 2 pool size mean?
The pooling window looks at 2 × 2 values at a time.
Does every modern CNN have a pooling
layer?
No. Spatial reduction can also be performed using
techniques such as strided convolution.