Skip to content
ML Visualization

Convolutional Neural Networks

Deep LearningAdvanced~11 min

Convolutional Neural NetworksA convolutional neural network (CNN) stacks convolution and pooling layers to turn raw pixels into a hierarchy of features — edges, then strokes, then whole shapes — and a final dense layer classifies the result. It is the architecture that made image recognition work.

Draw a digit and watch a real CNN take it apart: convolution layers light up as edge and stroke detectors, pooling shrinks the picture, and a final layer votes on which digit it is. Then rotate your digit and watch its confidence collapse — CNNs see patterns, not orientations.

Loading the trained network…

The idea in plain words

A convolutional neural network stacks the convolution operation into layers. Early layers learn simple kernels — edges and strokes; later layers combine those into whole shapes. Between them, pooling shrinks each feature map by keeping only the strongest response in each little neighborhood, which throws away exact position and keeps the “was this feature here?” signal.

Draw a digit and watch it happen: the eight feature maps are the network’s real layer-1 activations, and a final layer reads the pooled features to vote on which digit it is — the same idea as an MLP, but fed by learned image features instead of raw pixels. Then rotate your digit: pooling buys a little tolerance to shifts, but convolution shares weights across space, not orientation — so a rotated digit looks like a pattern the network never learned, and its confidence collapses.

Now, the math

The network is a short pipeline of convolution, nonlinearity, pooling, and a dense classifier:

a=ReLU(Wx+b)a = \mathrm{ReLU}(W * x + b)
p=maxpool2×2(a)p = \mathrm{maxpool}_{2\times 2}(a)
y^=argmaxksoftmax(Wdflatten(p)+bd)k\hat{y} = \arg\max_k\, \mathrm{softmax}\big(W_d\,\mathrm{flatten}(p) + b_d\big)_k
WxW * x
the convolution layer — a bank of learned kernels applied to the input.
ReLU\mathrm{ReLU}
the nonlinearity (see activation functions) that keeps only positive responses.
maxpool\mathrm{maxpool}
downsampling that keeps the strongest activation in each 2×2 window.
Wd,bdW_d, b_d
the final dense layer that turns pooled features into 10 class scores.
Show the derivation

The whole network is trained end to end with backpropagation: the same chain rule flows gradients back through the dense layer, the pooling (which routes the gradient only to the winning unit), and the shared convolution weights. Weight sharing means one kernel’s gradient is summed over every position it was applied — which is exactly why it learns a feature that generalizes across the image, and equally why it never learns to be invariant to rotation.

Now Break It

Try this: Rotate the drawn digit 90° and the network misclassifies it — convolution shares weights across space, not orientation.

Control: Distort control (rotate the digit)

What happens: CNNs aren’t rotation-invariant! Convolution shares weights across space, not orientation — so a rotated digit looks like a different pattern entirely.

Where convolutional neural networks is used

Convolutional neural networks are the reason computers can see. They power face unlock on phones, medical diagnosis from X-rays and retina scans, quality inspection on factory lines, handwriting and license-plate recognition, and the perception stack of self-driving cars. The same architecture, scaled up, underpins the image encoders inside modern multimodal AI systems. The digit classifier here is a miniature of exactly this pipeline: stacked convolutions and pooling turn raw pixels into features, and a dense layer reads them out.

The most common misconception is that a CNN “understands” an image the way a person does. It doesn’t — it detects a hierarchy of statistical patterns, which is why a digit rotated 90° or a photo with unfamiliar lighting can fool it even though it looks obvious to you. A second trap is assuming pooling makes the network fully invariant: pooling grants only small tolerance to shifts, not to rotation or scale. Finally, more filters and layers are not automatically better — without enough training data a bigger CNN simply overfits, memorizing the training images instead of learning general features.

Frequently asked questions

What is a feature map in a CNN?
A feature map is the output of applying one kernel across the whole input — a grid showing where that kernel found its pattern. A convolution layer with eight kernels produces eight feature maps, each highlighting a different feature such as horizontal edges, diagonal strokes, or blobs. The interactive shows these real activations lighting up for the digit you draw.
What does the pooling layer do?
Pooling downsamples each feature map by summarizing small neighborhoods — max pooling keeps the strongest activation in each 2×2 window. This shrinks the data, reduces computation, and makes the network slightly tolerant to where a feature appears, while keeping the signal that the feature was present.
Why is a CNN better than a plain neural network for images?
A fully-connected network treats every pixel independently and needs a separate weight for each, so it has enormous parameter counts and cannot recognize a shape that moves. A CNN shares small kernels across the image, so it uses far fewer parameters and detects features regardless of position — a much better match for how images are structured.
Why does rotating a digit break the CNN?
Convolution shares weights across space but not across orientation. The network learned kernels that fire for upright strokes; rotate the digit 90° and those same strokes now point a direction the kernels never saw, so the feature maps light up wrongly and confidence collapses. CNNs are not rotation-invariant unless you specifically train them with rotated examples.
Does this run a real neural network in my browser?
Yes. The weights were trained offline on the MNIST handwritten-digit dataset and shipped with the page; when you draw, a real convolutional forward pass runs live in your browser on your input — no server call. That is why you can see the actual feature maps and watch the prediction change stroke by stroke.

Written & reviewed by the ML Visualization team · Last updated .