+10−1+10−1+10−11for i in range(4):2 for j in range(4):3 fmap[i][j] = sum(4 x[i+r][j+c] * k[r][c]5 for r in range(3)6 for c in range(3))7out = maxpool(relu(fmap))001010010010010010010010000000000000denseverticalhorizontal03020302ΔwΔw
Khaki grid: the image · tall pixel = 1 (bright), low shaded pixel = 0 (dark)Rose block and frame: the 3×3 filter and its nine weightsBlue grid: the feature map · sand grid: the pooled map · chips carry one number eachA 6×6 image of ones and zeros and one 3×3 filter whose columns weigh +1, 0 and −1. At each of 16 positions the filter multiplies the nine pixels under it by its weights and adds them up; the 16 sums form a 4×4 feature map. ReLU turns its negatives into 0, and 2×2 max pooling keeps the largest number of each block. In front: more filters, and the dense layer that turns the pooled numbers into a class score. Strictly, CNN libraries compute cross-correlation: the filter is not flipped before it slides. They still call it convolution, and since the weights are learned, the difference does not matter.

Images and filters

  1. To a computer, an image is a grid of numbers, one per pixel (picture dot). Our tiny 6×6 image uses 1 for bright and 0 for dark. It shows a short vertical stroke, two pixels wide.

Convolution

ReLU and pooling

Deeper networks

What happens

;; step 1/10 · image
x (6x6), 1 = bright, 0 = dark
    0  0  1  1  0  0
    0  0  1  1  0  0
    0  0  1  1  0  0
    0  0  1  1  0  0
    0  0  0  0  0  0
    0  0  0  0  0  0

a real photo: 3 numbers per pixel (red, green, blue)

Strictly, CNN libraries compute cross-correlation: the filter is not flipped before it slides. They still call it convolution, and since the weights are learned, the difference does not matter. The final dense layer is shown, not computed: its weights would be learned too. The Python program is real; run it and it prints the feature map and the pooled 2×2 map.