Strides in CNN
Visualize how stepping the kernel by multiple pixels (Strides) acts as an efficient downsampling mechanism in Neural Networks.
Visualize how stepping the kernel by multiple pixels (Strides) acts as an efficient downsampling mechanism in Neural Networks.
In a Convolutional Layer, a kernel (filter) slides across the input pic to give a feature map. The Stride names just how many pixels this kernel shifts each time it moves.
By default, the stride is 1. The kernel moves 1 pixel to the right. And when it reaches the end of a row, it moves 1 pixel down. But what if we tell the kernel to jump 2 or 3 pixels at a time? This is called strided convolution. The output size follows the formula floor((input + 2*padding - kernel) / stride) + 1. So a stride of 2 roughly halves each spatial dimension and gives a feature map with one quarter the area. That reduction serves the same purpose as pooling — downsampling to capture more-scale features and reduce computation — but it does so inside the convolution it rather than in a split layer. Modern designs (ResNet, EfficientNet) often replace max-pooling with strided convolutions since the stride is a learned step (the filter weights are trained) while pooling discards information by a fixed rule. The tradeoff is that a more stride skips positions fully. So small features between steps are invisible to that layer. This page animates the kernel at other strides, shows the output dimensions updating live, and covers the interaction between stride and padding.
Visualize how stepping the kernel by multiple pixels (Strides) acts as an efficient downsampling mechanism in Neural Networks.
How taking bigger steps across an image reduces computational load and extracts higher-level features.
In a Convolutional Layer, a kernel (filter) slides across the input pic to give a feature map. The Stride names just how many pixels this kernel shifts each time it moves.
By default, the stride is 1. The kernel moves 1 pixel to the right. And when it reaches the end of a row, it moves 1 pixel down. But what if we tell the kernel to jump 2 or 3 pixels at a time? This is called strided convolution. The output size follows the formula floor((input + 2*padding - kernel) / stride) + 1. So a stride of 2 roughly halves each spatial dimension and gives a feature map with one quarter the area. That reduction serves the same purpose as pooling — downsampling to capture more-scale features and reduce computation — but it does so inside the convolution it rather than in a split layer. Modern designs (ResNet, EfficientNet) often replace max-pooling with strided convolutions since the stride is a learned step (the filter weights are trained) while pooling discards information by a fixed rule. The tradeoff is that a more stride skips positions fully. So small features between steps are invisible to that layer. This page animates the kernel at other strides, shows the output dimensions updating live, and covers the interaction between stride and padding.
If you process a massive high-resolution pic pixel-by-pixel, the resulting feature map will also be massive. This needs enormous amounts of memory and computational power.
By raising the stride, the kernel skips over sections of the pic. This dramatically shrinks the width and height of the resulting feature map. We call this downsampling. Downsampling forces the network to summarize local features (like corners or edges) into more-level, broader concepts, making the network faster and more reliable to slight shifts in the pic.
Stride is the step size the filter takes as it slides. Stride 1 moves one pixel at a time and looks at each possible position. Stride 2 skips each other position, halving the output in both dimensions.
out = floor( (in + 2×pad − kernel) / stride ) + 1
A 32×32 input with a 3×3 kernel and padding 1:
| Stride | Output | Positions computed |
|---|---|---|
| 1 | 32×32 | 1,024 |
| 2 | 16×16 | 256 |
| 3 | 11×11 | 121 |
| 4 | 8×8 | 64 |
Stride 2 cuts the output area to a quarter. And therefore cuts the computation of each later layer to a quarter as well. That compounding is why striding matters so much for cost.
Gained: computation and memory. Halving both spatial dimensions quarters the work. In a deep network the early layers are the costly ones, since the maps are largest. So downsampling early is where the savings are.
Gained: receptive field. After a stride-2 layer, each later filter covers twice as much of the first pic per step. Striding is one of the two ways a network gets a wide enough view to see whole objects (depth is the other).
Lost: spatial precision. Positions are skipped. So fine detail is discarded and cannot be recovered. For classification that is often acceptable — you want to know what, not just where. For segmentation and detection it is a real cost. And designs work hard to recover the lost resolution.
Lost: shift stability. Striding makes the network's output depend slightly on where the object sits relative to the sampling grid. Shift an pic by one pixel and a strided network can give a noticeably other prediction, an effect that has been measured and named — aliasing from downsampling without a low-pass filter.
Both reduce spatial size, and modern practice has moved from one to the other.
| Max pooling | Strided convolution | |
|---|---|---|
| Parameters | None | Learned |
| What it keeps | The strongest response in each window | Whatever the filter learns to keep |
| Cost | Very cheap | A convolution, so more |
| Used in | VGG, older architectures | ResNet and most modern designs |
The argument for strided convolutions is that downsampling is a decision. And a learned decision is often better than a fixed rule. The argument for pooling is simplicity and a small amount of built-in shift tolerance. In practice both work. And the gap is less than the design around them.
Global average pooling is a special case worth knowing: it collapses each feature map to a single count at the end of the network, replacing the flatten-and-dense head. It removes millions of params and makes the network accept any input size.
Leave Stride at S = 1. Click Slide Window. Watch the red box (kernel) move smoothly, pixel by pixel, across the input. The output feature map is 7x7. It's a dense, highly detailed form of the input.
Select S = 2. Notice the Output canvas instantly shrinks to 4x4. Click Slide Window again. Now watch the red box literally skip each other pixel. Since it's taking more steps, it needs fewer steps to cross the pic, giving a less, summarized output.
Select S = 3. The output shrinks to a tiny 3x3 grid. The kernel now just stops at 9 set locations on the whole input board. This is incredibly fast to compute. But notice how "blocky" and low-resolution the resulting feature map has turn.
Look at the formula box in the center. Notice the division step: $(W - K) / S$. The more the Stride ($S$) in the denominator, the drastically less the final Output ($O$) turns. The $⌊ ⌋$ brackets mean we round down (floor) if the kernel doesn't fit perfectly at the end of a row.
Assuming Padding (P) is 0, the output dimension ($O$) is calculated as:
O = ⌊(W - K) / S⌋ + 1
By manipulating strides, we force neural networks to transition from looking at individual pixels to recognizing high-level abstract shapes.
Segmentation, super-resolution and generative nets need to increase spatial size. And a stride of less than 1 is the idea — built as transposed convolution, sometimes misleadingly called deconvolution.
Conceptually it inserts zeros between the input pixels and then convolves. So a stride-2 transposed convolution doubles the resolution. The weights are learned. So the upsampling is adaptive rather than a fixed interpolation.
Its known weakness is checkerboard artefacts: when the kernel size is not divisible by the stride, some output positions get contributions from more input positions than others, giving a visible grid pattern. Two fixes are standard — make the kernel size a multiple of the stride (4×4 with stride 2). Or use nearest-neighbour upsampling followed by an ordinary convolution. It avoids the problem fully and is now the more common choice.
There is a third way to widen the receptive field, distinct from both stride and depth. Dilated (or atrous) convolution spreads the filter's taps apart. So a 3×3 kernel with dilation 2 covers a 5×5 area while still with just nine weights.
The output size is unchanged. So nothing is downsampled and no resolution is lost. Stacking layers with dilations of 1, 2, 4 and 8 grows the receptive field exponentially while keeping full resolution throughout.
This is why dilated convolutions are standard in semantic segmentation (DeepLab) and in audio nets such as WaveNet. There the network needs a very wide view of a long signal without throwing away detail.
A stride is how far the kernel jumps between applications. It shrinks the output, cuts the compute quadratically. And throws away information that no later layer can recover.
Building on the same setup, the next block shows the left cases.
The next block covers the left steps.
The next block continues with the left demonstrations.
Building on the same setup, the next block shows the left cases.
What stride should I use? 1 for the convolutions that extract features, 2 where you deliberately want to halve the resolution. Strides above 2 are rare outside the very first layer of some networks.
Why do some networks use stride 2 in the first layer? Since the input is large and the early layers are the most costly. ResNet's first layer is a 7×7 convolution with stride 2, at once followed by a stride-2 pool, cutting 224×224 to 56×56 before the real work begins.
Does stride affect the count of params? No. The filter is the same size. Just how often it is applied changes.
Can stride be other per dimension? Yes — (2, 1) halves the height and preserves the width. It is used in spectrogram nets where the two axes mean other things.
How do I recover resolution after striding? Transposed convolution or upsampling, often mixed with skip connections from earlier, more-resolution layers — which is just what U-Net does.
Is striding the same as pooling? Both downsample. Pooling applies a fixed rule with no params. Strided convolution learns what to keep.
Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.
What does this module say about “What is a Stride”?
What does this module say about “Why use more strides? (Downsampling)”?
What does this module say about “How far the filter jumps”?
Increase the stride from 1 to 2 and watch the feature map shrink to a quarter of its area in a single convolution step.