podqast
Machine Learning GuideOCDevelAll episodes

MLG 025 Convolutional Neural Networks

44 min
Next episodeMLG 026 Project Bitcoin Trader39 min
Get its new episodes on Latest. No account

A convolutional neural network slides small learned filters across an image, each making a feature map that is high where its pattern appears, and stacks these layers so later ones find larger patterns. Also covers window size, stride, same and valid padding, max pooling, and the CNN line from LeNet-5 to the ImageNet winners AlexNet, GoogLeNet and ResNet.
Links • Notes and resources at ocdevel.com/mlg/25

Why not use an MLP for images? A multilayer perceptron (MLP) flattens an image into a list of pixels and connects every pixel to every neuron of its first dense layer, each connection with its own weight. Nothing in that design tells it that neighboring pixels belong together, and a pattern it learns in one corner has to be learned again for every other position. A convolutional neural network (CNN, or ConvNet) builds both in: each neuron looks only at a small window of neighboring pixels, and the same filter is reused at every position, so a striped shirt is found wherever Waldo stands. That's why CNNs took over from MLPs for vision.
An 8-bit grayscale image stores each pixel as 0 (black) to 255 (white); scaled to 0–1, 1 is white. A color image has three channels, red, green and blue, so the input is a width × height × 3 volume.
What is a filter? A filter, or kernel, is a small grid of learned weights, say 5×5, that spans every channel of its input: a 5×5 filter on an RGB image holds 5×5×3 weights plus a bias. At each position it multiplies the window's values by its weights, sums the products, adds the bias, and usually passes the result through a ReLU. Weights can be negative, so a horizontal-stripe detector has rows of positive weights alternating with rows of negative ones. It responds strongly where light and dark stripes line up with it and weakly elsewhere.
Training learns the weights by backpropagation. You choose how many filters a layer has and their size. Filters in early layers tend to learn edges and color blobs, later ones textures and parts of objects.
Filter, feature map and convolutional layer • Filter: the small grid of learned weights.

A classifier CNN stacks convolutional layers, shrinking width and height while depth grows, then ends in dense layers with a softmax or sigmoid output. Many modern CNNs replace the big dense layers with global average pooling, which averages each feature map to one number, followed by a single dense layer.
Window, stride and padding The window is the filter's size; the stride is how far the filter moves between positions. For input width W, filter size F, padding P and stride S:
output width = (W − F + 2P) / S + 1 • Stride 1 moves one pixel at a time, so neighboring windows overlap heavily.

Padding adds zeros around the border, on every side. "Same" padding adds enough that at stride 1 the output keeps the input's width and height (P = (F − 1)/2 for an odd F). "Valid" padding adds none, so the filter only visits positions where it fits entirely, and at stride 1 the output shrinks by F − 1.
What does p

More from Machine Learning Guide