0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09How does a network see a mug?
Brightcart has fifty thousand product photos, and Sana needs each one tagged: mug, lamp, kettle, cushion. By hand, that's weeks of work. To a computer, a photo is just a grid of numbers. Zoom in far enough on this mug and you see it: every pixel is three numbers, how much red, green and blue, each from zero to two hundred and fifty-five. Now here's the problem. Shift the mug a few pixels to the right, and almost every one of those numbers changes. Yet it's obviously still a mug. A good image model has to recognise patterns wherever they appear.
Today we meet the operation that solved this and launched modern computer vision: the convolution. And by the end, you'll compute one by hand.
0:59Where we are on the map
Season Two, Module Eight: computer vision. First stop: convolutions.
1:06Why not a dense layer? 150 million weights
Why not use the dense networks we already know? Let's count. A modest colour photo, two hundred and twenty-four pixels square, has a hundred and fifty thousand five hundred and twenty-eight numbers. Connect them all to just a thousand neurons, and that single layer has over a hundred and fifty million weights. Far too many to learn from fifty thousand photos. There are two deeper problems. A dense layer has no idea that neighbouring pixels belong together. Scramble every pixel in the same fixed way, and a dense network learns just as well, which means it isn't using the structure of the image at all.
And a pattern it learns in one corner, like the curve of a handle, has to be learned all over again for every other position. We need a layer that looks at small neighbourhoods, and reuses what it learns everywhere. That's a convolution.
2:05The convolution: a sliding dot product, by hand
A convolution uses a small grid of weights called a filter, or kernel, here three by three. We slide it across the image, and at each position we do something you know very well: multiply the filter's numbers by the pixels underneath, and add everything up. A dot product, again. Let's do it by hand. Our tiny image is six by six: dark on the left, value zero, and bright on the right, value nine. There's a vertical edge down the middle. Our filter has minus ones on its left column, zeros in the middle, and plus ones on the right.
At the top-left corner, every pixel under the filter is zero, so the result is zero. Slide one step to the right. Now the filter's right-hand column sits on the bright pixels. Each row gives minus one times zero, plus zero times zero, plus one times nine: nine. Three rows: twenty-seven. Keep sliding, and we get a new grid: zeros where the image is flat, and twenty-sevens exactly where the edge is. This filter is a vertical-edge detector. It lights up where brightness changes from left to right.
3:22Filters are learned
Different filters detect different things. Swap the columns for rows and you get a horizontal-edge detector. Fill it with ninths and it blurs. Other patterns sharpen. Here's the key idea of a convolutional neural network, or C-N-N: we don't design the filters. Their numbers are weights, learned by backpropagation, exactly like the weights of the digit reader. The network discovers which patterns are useful for its task. And remarkably, when researchers look at the first layer of trained image networks, they often find filters that look like edge and colour detectors, much like the ones engineers used to design by hand.
4:08Channels and feature maps
Real photos have three colour channels, red, green and blue, stacked like slices. So a filter for a colour image is really three by three by three: one slice per channel. It multiplies and sums across all three, producing a single number at each position. A convolutional layer uses many filters at once, say sixteen, each looking for a different pattern. Each filter produces its own output grid, called a feature map, so the layer's output is a stack of sixteen maps. And here's the payoff. That whole layer has just four hundred and forty-eight parameters: twenty-seven weights and a bias per filter, times sixteen filters.
Compare that with over a hundred and fifty million for the dense layer. The next layer, from sixteen maps to thirty-two, needs four thousand six hundred and forty.
5:04Stride and padding (output-size formula)
Two settings control the size of the output. Notice that our six-by-six image became four by four: a three-by-three filter can't centre itself on the border pixels, so the output shrinks. To prevent that, we add padding, a border of zeros around the image. With a three-by-three filter and one pixel of padding, a twenty-eight-by-twenty-eight image stays twenty-eight by twenty-eight. The stride is how far the filter jumps each time. With a stride of two, it skips every other position, and the output is roughly halved: twenty-eight becomes fourteen.
There's a formula: the input size plus twice the padding, minus the filter size, divided by the stride, plus one. Pause and predict: a thirty-two pixel image, a five-by-five filter, no padding, stride one. What's the output size?
Thirty-two minus five, plus one: twenty-eight.
6:10Max pooling
After convolutions and a ReLU, networks often shrink the feature maps with pooling. The most common kind is max pooling: split the map into two-by-two blocks and keep only the largest value in each. This four-by-four grid becomes six, two, two, nine. Pooling does three helpful things. It makes the maps smaller, saving computation. It makes the network a little more tolerant of small shifts: if a pattern moves by a pixel within a block, the maximum is often the same. And it has no parameters to learn. Our edge map pools down to a small grid of twenty-sevens: the edge is still there, just more compact.
Some modern networks use convolutions with a stride of two instead, and many end with a global average pooling layer that averages each whole map into a single number.
7:06Why convolutions fit images
So why do convolutions suit images so well? Three reasons. Local connectivity: each output only looks at a small neighbourhood, because nearby pixels are what form edges and textures. Weight sharing: the same filter is used at every position, so a handle detector learned once works anywhere in the image, with a tiny number of parameters. And translation equivariance: shift the mug in the input, and its features shift by the same amount in the feature map. The pattern is found wherever it is. One honest caveat: convolutions don't automatically handle rotations or big changes in size.
A mug upside down or very small can still confuse them. We help with that by showing the network varied training examples, called data augmentation, coming next episode.
8:00Stacking layers: receptive fields
Stack convolutional layers and something wonderful happens. A neuron in the first layer sees a three-by-three patch of the image. A neuron in the second layer sees three-by-three patches of the first layer's maps, which together cover five-by-five pixels. By the third layer, each neuron sees seven-by-seven. That region is called the receptive field, and it grows with depth. That's why modern networks use small three-by-three filters, stacked. Three of them cover a seven-by-seven area with twenty-seven weights instead of forty-nine, and add two extra ReLU bends along the way.
And it creates a natural hierarchy. Early layers detect edges, middle layers combine them into corners, curves and textures, and deeper layers respond to whole parts, like handles and spouts, and eventually whole objects, like mugs and kettles.
8:59Try it yourself: a horizontal-edge filter
Let's test a different filter: minus ones along the top row, zeros in the middle, plus ones along the bottom. It detects horizontal edges. What does it output on our image with the vertical edge? Pause and predict. All zeros. Going from top to bottom, nothing changes in that image, so there's no horizontal edge to find. Now apply it to an image that's dark on top and bright at the bottom: the output is a stripe of twenty-sevens, exactly along the horizontal edge. Each filter asks one question, "is my pattern here?", and answers it at every position.
9:44Try it yourself: track the shapes
Now a shape puzzle, the kind you'll meet in every vision model. A two-hundred-and-twenty-four-pixel colour photo goes through a convolution with sixty-four three-by-three filters, padding one, stride one. What's the output shape? Still two hundred and twenty-four by two hundred and twenty-four, but now sixty-four channels deep, one map per filter. Then a two-by-two max pool with stride two? A hundred and twelve by a hundred and twelve by sixty-four. Width and height come from padding, stride and pooling; depth comes from the number of filters.
10:25How a CNN learns its filters
How do filters become edge detectors? Through exactly the training loop we already know. Backpropagation works through convolutions too: because the same filter is used at every position, each filter weight collects gradient contributions from every place it was applied, all added together. At the start of training, the filters are random noise. As training proceeds, the ones in the first layer gradually turn into detectors for edges, colour blobs and simple textures, because those help the network reduce its loss.
11:02Dilated, 1×1 and depthwise convolutions
A few useful variations. A dilated convolution spreads its filter out with gaps, so nine weights cover a wider area, handy when a network needs a broad view without losing resolution. A one-by-one convolution doesn't look at neighbours at all; it mixes the channels at each pixel, a cheap way to reduce, say, two hundred and fifty-six channels to sixty-four. And depthwise-separable convolutions filter each channel separately and then mix them with a one-by-one, cutting the computation dramatically, which is why they're popular in networks designed for phones.
11:42Convolutions beyond images
Convolutions aren't only for images. A one-dimensional convolution slides a filter along a sequence, like Brightcart's daily sales, to detect weekly patterns, or along an audio waveform. Before transformers took over, convolutions slid over word embeddings to detect phrases like "not good". And three-dimensional convolutions handle video, where time is the third dimension, or medical scans. Wherever nearby values belong together, convolutions apply.
12:15Common CNN mistakes
Some mistakes are specific to image models. Feeding raw pixel values from zero to two hundred and fifty-five instead of scaled values. Mixing up the order of the colour channels, or the image size, compared with what the model was trained on. Pooling too aggressively too early, losing small details like a hairline crack in a mug. And leakage: near-identical product photos, the same mug from slightly different angles, ending up in both the training and test sets, which makes test scores look far better than reality.
12:50Myth vs Fact
Myth: a CNN sees images the way we do. Fact: it responds to numerical patterns it learned from its training data. Networks can lean heavily on texture rather than shape, and carefully crafted, nearly invisible changes to pixels can sometimes fool them completely. They're extremely powerful, but they don't see like humans.
13:13Recap
Let's recap. An image is a grid of numbers with colour channels. A convolution slides a small filter across it, computing a dot product at every position, and the filter's values are learned. Many filters produce many feature maps, with a tiny fraction of the parameters a dense layer would need. Padding and stride control the output size, and pooling shrinks the maps. Convolutions look locally, share weights everywhere, and shift along with the input. And stacking them grows the receptive field, from edges to objects.
One sentence to remember: one small filter, slid everywhere, learns what to look for.
13:56Next: CNN architectures and transfer learning
Mission complete. We have the building blocks of computer vision: convolution, ReLU and pooling, and we detected an edge by hand. Next, we'll assemble them into complete networks, following the famous architectures that took image recognition from reading zip codes to beating human benchmarks. And we'll learn the trick that lets Brightcart train a great photo classifier with only a few thousand labelled images: transfer learning. See you on the map.