Ch 3 ▸ Stride, padding and dilation ▸ Module 1/4
Stride.
Stride is how far the kernel moves between one output and the next, counted in pixels. With stride 1 the kernel moves one pixel at a time and stops at every position it fits. With stride 2 it moves two pixels at a time, so it skips every other position.
Counting the outputs
Every position where the kernel stops produces one output, so counting outputs means counting stops. Take a single row of 16 pixels, numbered 0 to 15, and a kernel 3 pixels wide.
The kernel’s left edge can start at pixel 0. The latest it can start is pixel 13, because a kernel starting there covers pixels 13, 14 and 15, the last three. Any later and it would hang off the end of the row. In general, the last start is the row length minus the kernel width: 16 − 3 = 13.
From there, stride decides which starts between 0 and 13 the kernel actually uses:
- Stride 1: 0, 1, 2, …, 13. That’s 14 outputs.
- Stride 2: 0, 2, 4, …, 12. That’s 7 outputs. The next stop would be 14, which is past 13.
- Stride 3: 0, 3, 6, 9, 12. That’s 5 outputs.
Columns work exactly the same way, so a 16×16 image gives a 14×14 output map at stride 1, 7×7 at stride 2 and 5×5 at stride 3. Check these against figure 3.1b.
Why use a bigger stride
Going from stride 1 to stride 2 roughly halves the outputs along each axis. The map is two-dimensional, so the total drops to roughly a quarter: 14 × 14 = 196 outputs become 7 × 7 = 49.
Making a map smaller like this is called downsampling: the new map has fewer values, and each one summarizes a bigger patch of the original. Downsampling makes every later layer cheaper to compute. Stride is the simplest way to do it, because the convolution and the shrinking happen in a single step.
Stride 3 shows the catch. Its last start is pixel 12, which covers pixels 12 to 14, so pixel 15 is never read at all. Whenever the stride doesn’t divide evenly into the room available, the leftover pixels at the far edge are skipped. You’ll see this rounding again when the settings come together in the last module.
Knowledge check ▸ 3 questions
Before you move on.
Answer every question correctly to unlock the next module. A wrong answer gets a hint, and you can try again as many times as you like.
1What does stride control?
2A row of 20 pixels, a kernel 3 pixels wide, stride 2. How many outputs does the row produce?
3Going from stride 1 to stride 2, the total number of output values becomes roughly…