Stride, Padding & Pooling
Control output size and downsample.
Stride, Padding & Pooling is a free Deep Learning Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Deep Learning Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Output Shrinks by Default
When a 3x3 kernel slides over an image, the edges have no room. So the output feature map comes out a little smaller than the input.
Padding Adds a Border
Padding wraps the image in a ring of zeros so the kernel can reach the corners. Now the output can stay the same size as the input.
Same Padding in Code
For a 3x3 kernel, padding of 1 keeps the spatial size unchanged. People call this same padding.
conv = nn.Conv2d(3, 16, kernel_size=3, padding=1)Stride Sets the Step Size
Stride is how far the kernel jumps each move. A stride of 1 visits every position; a larger stride skips ahead.
Stride 2 Halves the Map
With stride 2 the kernel hops two pixels at a time, so the output is roughly half the width and height. It is a cheap way to downsample. ⬇️
Stride and Padding Together
Combine them to control the exact output size. Here stride 2 with padding 1 downsamples while keeping the corners covered.
conv = nn.Conv2d(16, 32, 3, stride=2, padding=1)Why Downsample at All?
Shrinking the maps cuts computation and lets later layers see a wider region of the original image with each kernel.
Pooling: Another Way to Shrink
Pooling downsamples too, but with no learned weights. It just summarizes each small patch into a single value.
Max Pooling Keeps the Strongest
Max pooling takes the largest value in each 2x2 patch. It keeps the strongest signal and quietly drops the rest.
pool = nn.MaxPool2d(kernel_size=2)Average Pooling Smooths
Average pooling takes the mean of each patch instead of the max, giving a smoother, gentler summary of the region.
pool = nn.AvgPool2d(kernel_size=2)Pooling Adds Small Invariance
Because pooling summarizes a patch, a tiny shift in the input barely changes the output. This gives a touch of translation invariance.
Quick Check
Let us test what padding actually does for a convolution.
Recap: Control the Shape
You learned that padding preserves size, stride sets the step and downsamples, and pooling shrinks maps while adding a little shift tolerance. 🎯
Frequently asked questions
Is the “Stride, Padding & Pooling” lesson free?
Yes — the full text of “Stride, Padding & Pooling” is free to read here on the web, and the Deep Learning Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Deep Learning Academy course, upgrade to CoddyKit PRO.
What will I learn in “Stride, Padding & Pooling”?
Control output size and downsample. You practise Deep Learning Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Deep Learning Academy?
No prior experience is required. Deep Learning Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Stride, Padding & Pooling” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Deep Learning Academy lesson?
Yes. Every Deep Learning Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.