Interactive demo · Probabilistic Machine Learning · Chapter 14

Convolution as a matrix: padding, stride, dilation and the transposed layer

A convolutional layer is an ordinary linear map y = Cx, but with a matrix C that is mostly zeros and whose non-zero entries are copies of the same k×k kernel (Equations 14.8 and 14.9). Pick an image and a kernel, set the padding p, stride s and dilation r, and click an output pixel. The top row shows the (zero-padded) input with the taps the kernel reads for that pixel, the output feature map, and CTy, the transposed convolution of the output, in which every output pixel stamps a weighted copy of the kernel back onto the input grid. The bottom panel is the matrix C with the row of the selected output pixel marked.

Image

Kernel

Kernel size k

Padding p

Stride s

Dilation r

Try these

The layer is the cross-correlation (14.5), as in deep-learning libraries. Kernels for any size k: edge has columns −1 | 0 | +1 (the sign of the column offset from the centre), blur has every weight 1/k2, diagonal is the identity matrix divided by k. The digits are MNIST test images averaged down to 14×14. Zero padding adds a border of p zeros on every side. Click an output pixel (or tap it) to choose which row of C is marked.

In the lecture notes