§9.0–9.1Convolutional Networks · The Convolution Operation

Part II DL pp. 330–334 · ~3 min read

  • convolution
  • kernel
  • feature map
  • cross-correlation
  • discrete convolution

§9.0 Networks for grid-structured data

Convolutional networks (CNNs, LeCun 1989) are neural networks specialized for data with a known, grid-like topology: a 1-D grid of time samples, a 2-D grid of image pixels, a 3-D volume. The name says it all — they use a mathematical operation called convolution (a special kind of linear operation) in place of general matrix multiplication in at least one of their layers. They have been enormously successful, and the best architectures are consistently built from the handful of building blocks in this chapter.

§9.1 The convolution operation

Convolution starts as a weighted average. Imagine a noisy laser sensor reporting a spaceship’s position x(t)x(t); to smooth it, average recent readings with a weighting w(a)w(a) that favors newer measurements. Applied at every instant, that gives s(t)=x(a)w(ta)da=(xw)(t)s(t) = \int x(a)\,w(t-a)\,da = (x * w)(t). The first argument xx is the input, the second ww is the kernel , and the output ss is the feature map . On a computer, everything is discrete and multidimensional — for a 2-D image II and 2-D kernel KK:

Term by term

S(i,j)=(IK)(i,j)=mnI(i+m,j+n)K(m,n)S(i,j) = (I * K)(i,j) = \sum_m \sum_n I(i+m,\, j+n)\, K(m,n)
I(i+m,j+n)I(i+m, j+n)the input PATCH sitting under the kernel when its top-left corner is at output position (i,j)the patch
K(m,n)K(m,n)the small kernel of learned weights — the SAME weights reused at every position (parameter sharing)the kernel
mn\sum_m\sum_neach output cell is the dot product of the overlapped patch with the kernel. (This is the CROSS-CORRELATION form — no kernel flip — which most libraries call “convolution”)multiply & sum

Watch it happen — slide the kernel over the image and each output cell is the patch-times-kernel sum. Switch kernels to see different features light up:

Fig 9.1 (interactive) — 2-D convolution: click an output cell to see the input patch and its multiply-and-sum. The vertical-edge kernel fires on the dark→bright boundary
input (5×5)
2
3
7
8
8
1
2
8
9
7
3
2
7
8
9
2
1
8
7
8
1
3
7
9
8
kernel
-1
0
1
-1
0
1
-1
0
1
output (3×3)
16
18
2
17
19
1
16
18
3
output[1][1] = Σ (patch ⊙ kernel)
= 19
click any output cell to slide the kernel

Each output cell is the sum of the overlapped input patch times the kernel. Slide across the image and the same small kernel detects its feature everywhere — the vertical-edge kernel lights up the dark→bright boundary. Flipping the kernel is the only difference between convolution and the cross-correlation libraries actually use.

Convolution vs cross-correlation — the flip

True convolution flips the kernel: as mm increases, the input index increases but the kernel index decreases. This flip is what makes convolution commutative (IK=KII*K = K*I) — handy for proofs, but irrelevant in practice. So most machine-learning libraries implement cross-correlation (no flip) and simply call it convolution. It does not matter which you use: the learning algorithm just learns a kernel that is flipped relative to the other convention. Toggle “flip kernel” above — for a symmetric kernel (identity) nothing changes; for the edge kernels the output flips sign/orientation.

Finally, a useful lens: a discrete convolution is just matrix multiplication by a structured matrix. For 1-D convolution that matrix is a Toeplitz matrix — each row equals the row above, shifted by one element; in 2-D it is a doubly block circulant matrix. The single small kernel is copied into many entries of a huge, mostly-zero (sparse) matrix — which is exactly why convolution is so much cheaper than a dense layer, as the next section shows.

Next: why convolution helps — sparse interactions, parameter sharing, and equivariance — the motivation for convolution.

Check yourself — the convolution operation

1.What makes a network 'convolutional', and what kind of data is it for?

2.In the 2-D formula S(i,j) = Σ I(i+m,j+n)K(m,n), what is each output cell?

3.In ConvLab, click different output cells with the vertical-edge kernel. Why do the cells over the dark→bright boundary have large values?

4.What is the difference between convolution and cross-correlation, and does it matter in practice?

5.In what sense is a discrete convolution a matrix multiplication, and why does that explain its efficiency?

5 questions