Convolution by hand
Why it matters One small set of weights, slid across the whole image, finds the same pattern everywhere. That one idea fixes what you just saw break.
See it
Play the animation. A 3 by 3 grid of weights, the filter, sits on the top-left corner of the image. Multiply each of the 9 pixels under it by the weight on top of it and add them up: that is one output number. Slide one step right and do it again. When the filter has visited every position, the outputs form a new, slightly smaller image called a feature map.
Tiny numbers
The filter [[-1, 0, 1]] * 3 rows responds to left-to-right brightness changes: on a patch that is dark on the left and bright on the right it gives a big positive number; on a flat patch it gives 0. It is an edge detector, and in a CNN such filters are learned, not written by hand.
Filter (kernel): the small grid of weights. Valid convolution: only positions where the filter fits fully inside the image, so an n by n image and a k by k filter give (n - k + 1) by (n - k + 1).
Words and symbols in this lesson
- convolution
- sliding a small grid of weights (a filter) across an image, one dot product per position
- filter, feature map
- the small learned grid of weights; and the image of its responses
Write conv2d(img, k): valid convolution (the deep learning kind, which does not flip the filter) of a 2D image with a 2D filter, using loops over the output positions.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.