Notes

Stride

Imagine scanning a small window across a grid of values. Stride is the distance that window moves after each scan. A stride of 1 examines every adjacent position; a stride of 2 skips ahead by two positions, producing a smaller output.

How it works
In a convolutional layer, a kernel computes one number at each location it visits. Stride controls the spacing of those locations along height and width. For a one-dimensional input of size n, kernel size k, padding p, dilation d, and stride s, the output length is:

floor((n + 2p - d(k - 1) - 1) / s + 1)

For example, a 32×32 input processed with a 3×3 kernel, padding 1, and stride 1 remains 32×32. With stride 2, it becomes 16×16. Frameworks such as PyTorch express this directly: nn.Conv2d(..., stride=2). Stride can differ by axis, such as stride=(2, 1), though equal strides are more common.

Why it changes the network
Stride greater than 1 performs downsampling while extracting features. This reduces the number of output activations, so later layers use less memory and computation. It also expands the spacing between sampled locations in the original input, helping a deep network build broader, less detail-focused representations. Pooling layers have a stride for the same reason: it specifies how far the pooling window advances.

Training and design consequences
A large stride too early discards fine spatial detail before later layers can use it. Small objects, boundaries, or precise locations can vanish simply because no output position sampled them. Strided operations can also introduce aliasing: high-frequency patterns become misleading when sampled too sparsely. A common design uses stride 1 in early feature extraction, then deliberate stride-2 layers to reduce resolution. In a ResNet block that downsamples, the shortcut path also uses stride 2, ensuring its shape matches the main path before the two are added. Stride therefore trades detail for efficiency; it is not a learned parameter, but it strongly determines what information the learned parameters can preserve.

Stride is the number of positions a convolution or pooling window moves between successive applications across an input. A stride of 1 evaluates adjacent positions; larger strides skip positions and produce smaller output feature maps. Stride controls spatial downsampling, computational cost, and receptive-field spacing: excessive stride discards fine detail, while smaller stride preserves resolution at greater cost.

Imagine scanning a large photograph with a small magnifying window. After looking at one spot, you slide the window across the picture. Stride is how far you move that window each time.

In an image-recognising network, the window looks for useful patterns such as edges, textures, or parts of an object. A stride of 1 means it moves one pixel at a time, examining the image very closely. A larger stride skips farther ahead, so it scans faster and produces a smaller, less detailed map of what it found.

So stride helps balance detail against speed and size: small steps notice more; bigger steps cover the image more quickly.