= Convolution stride
{title2=$s$}
The <convolution stride> specifies how far the filter's origin advances between neighboring output positions of a <convolutional layer>. It controls which spatial positions are evaluated. A larger stride usually produces a smaller output grid without changing the number of coefficients in each filter.<Conv2d in the PyTorch documentation>[stride parameter and Shape]{ref}
For a real one-dimensional example, take the input
$$
x=(1,2,4,8,16,32,64)
$$
and a size-three all-ones filter, no bias and no padding. Using the unflipped <cross-correlation> convention, stride one evaluates windows beginning at indices $0,1,2,3,4$ and gives
$$
y=(7,14,28,56,112).
$$
Stride two evaluates windows beginning at indices $0,2,4$, giving
$$
y=(7,28,112).
$$
The second result keeps every second origin from this first grid; it still combines three input values for each retained origin.
For an undilated length-$L$ input and length-$k$ filter, no padding and stride $s$, a zero-indexed output $t$ uses input indices $st$ through $st+k-1$. Requiring its last index not to exceed $L-1$ gives $st\leq L-k$. Counting the admissible nonnegative integers $t$ therefore gives
$$
L_{\mathrm{out}}=\left\lfloor\frac{L-k}{s}\right\rfloor+1
$$
when $L\geq k$ and $s$ is a positive integer. The <floor function> is essential when the last candidate origin would extend beyond the input.
With symmetric <zero padding> of $p$ positions per side and <convolution dilation> $d$, the corresponding standard shape expression is
$$
L_{\mathrm{out}}
=\left\lfloor\frac{L+2p-d(k-1)-1}{s}\right\rfloor+1.
$$
Here dilation changes the spacing of samples within a filter footprint; stride changes the spacing between filter origins. The two parameters have different roles.<Conv2d in the PyTorch documentation>[Parameters, stride/padding/dilation; Shape, each spatial-axis formula]{ref}
For two-dimensional data, specify a stride for each spatial axis; unequal strides need not reduce height and width by the same amount. The weights of the filter remain shared across the visited positions. Stride also changes how neighboring outputs' <neural network receptive fields> are spaced in the original input, so it affects more than just a displayed array size.
Back to article page