Skip to main content

Lesson 4 of 12

Pooling Layers

Pooling layers reduce the spatial size of feature maps, making the network more efficient and providing some translation invariance — so features are detected regardless of small position changes.

6 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Max Pooling

Max Pooling
import cv2
import numpy as np

# POOLING: downsample a feature map by taking the max (or average)
# in each non-overlapping region

feature_map = np.array([
    [1,  3,  2,  4],
    [5,  6,  1,  2],
    [2,  4,  3,  7],
    [8,  1,  4,  2],
], dtype=np.float32)

print("Original feature map (4x4):")
print(feature_map)
print()

# 2x2 max pooling: take the maximum from each 2x2 block
def max_pool_2x2(feature_map):
    h, w = feature_map.shape
    h_out, w_out = h // 2, w // 2
    output = np.zeros((h_out, w_out))
    for i in range(h_out):
        for j in range(w_out):
            block = feature_map[i*2:(i+1)*2, j*2:(j+1)*2]
            output[i, j] = block.max()
    return output

pooled = max_pool_2x2(feature_map)
print("After 2x2 max pooling (2x2):")
print(pooled)
print()

# Effects of pooling:
print("Pooling effects:")
print(f"  Original: {feature_map.shape} → Pooled: {pooled.shape}")
print(f"  Parameters reduced by 4x")
print("  Translation invariance: small shifts in the feature position")
print("  are absorbed — the max in the region still activates")
Diagram
Loading diagram…

Machine Learning follows a structured pipeline from data to deployment

Finished this lesson?

0 of 12 in Module 11
Sign in to save progress

Topics in This Module

0/12 done