liveBook · Manning

Zero padding

As explained in Math and Architectures of Deep Learning

A convolution setting that extends the input with zeros so the kernel can produce outputs near the boundary.

Zero padding extends an input array with zeros so a convolution kernel can continue producing outputs near the boundary. With p zeros on each side, an input of size n becomes n + 2p; the kernel then slides across this enlarged array. section 10.2 section 10.8

For valid padding, convolution stops when any kernel element would leave the input. Zero padding instead treats positions outside the array as zero, allowing boundary windows and changing the output size. The same idea extends independently across each dimension of 2D and 3D inputs. section 10.2 section 10.8

A boundary convolution

With a kernel [w0, w1, w2], zero padding lets the final window use [x(n−1), 0, 0]. Its output is y(n−1) = w0 · x(n−1) + w1 · 0 + w2 · 0. The padded values preserve a final output position even though most of the kernel lies beyond the original input. section 10.1.3

ms + (k − 1) ≤ (n − 1)

Use the boundary-position inequality to see when a shifted kernel remains within the effective, padded input. section 10.2

How Math and Architectures of Deep Learning covers it

How deep it goes
Derives padded input size and boundary positions, but stops short of implementation-specific padding configuration.
Examples
Uses a one-dimensional kernel of size three and a final window containing one input value followed by two zeros.
What it assumes
Assumes familiarity with convolution kernels, strides, input arrays, and sliding local windows.
What you can do after
Apply it to reason about boundary outputs and calculate how padding changes the effective convolution input.
How it connects
Links convolution with kernel size, stride, valid padding, same padding, and matrix multiplication.

Also explained in

Compare how 2 books explain zero padding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.