Padding and Stride

Padding adds values around the input border.

Stride controls how far the kernel moves each step.

padding changes borders; stride changes step sizestep 1step 2step 3padded borderstride skips positions
Padding controls edge handling; stride controls how far the kernel moves each step.

Without padding, a kernel cannot be centered at the border in the same way it can be centered inside the input. Padding lets the layer produce outputs near edges.

Stride changes output size. In one dimension, a simple valid convolution output length is:

output_length = floor((input_length - kernel_size) / stride) + 1

For input_length = 7, kernel_size = 3, and stride = 2:

floor((7 - 3) / 2) + 1 = 3
DL-C14-T04-001Exercise: Valid output length

For input length 8, kernel size 3, and stride 1, what is the valid convolution output length?

Compute it first, then check your number.

DL-C14-T04-002Exercise: Stride two

For input length 9, kernel size 3, and stride 2, what is floor((9 - 3) / 2) + 1?

Compute it first, then check your number.