Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Neural networks / How neural networks learn

Image classification: recognising more than digits

Reading a digit is one thing. Recognising a dog in a photograph is another. How far can the same idea take us?

Builds on Seeing digits.

We now know how to turn a picture into a digit. But what if we want more than ten answers? Instead of reading digits, what if we want to classify photographs: is this a dog, a bicycle, a teapot?

That is a harder problem in two ways. The pictures are in colour, and there are a thousand things to name, not ten.

A photo is three pictures

A colour picture is three grids of numbers: how much red, how much green and how much blue is in each pixel.

A colour picture is three pictures

Interactive

A photo 227 pixels across has 227 × 227 × 3 = 154,587 numbers. A single neuron looking at all of them would need 154,587 weights. But the recipe from the last article does not change. A filter is still a small patch, 3 or 5 or 11 pixels across, now looking through all three colours at once.

A thousand things

The labelled training set is ImageNet (Deng et al., 2009): 1.2 million photographs, each labelled with one of 1,000 classes. Dogs of many breeds, vehicles, tools, foods.

The same recipe, scaled up

In 2012, Alex Krizhevsky, Ilya Sutskever and Geoffrey Hinton entered a network called AlexNet in the ImageNet competition. It is the digit reader with two main changes.

It is larger, with more layers. The digit reader had two convolution layers. AlexNet has five, with up to 384 filters each, and its filters look through all three colours. After them come two dense layers of 4,096 neurons.

The last layer has 1,000 neurons, not ten. The digit reader had one neuron for each digit. AlexNet has one for each of the 1,000 classes in the labelled training set. Softmax turns their scores into probabilities, exactly as before.

AlexNet: the same recipe, scaled up

Interactive

Everything else is the same recipe: filters slid over the picture, ReLUs, and learning by guessing, measuring and nudging.

Did it work?

AlexNet’s top-5 error (the right answer missing from its five best guesses) was 15.3%. The runner-up’s was 26.2%. The gap marked a turning point in computer vision: it showed how well a large convolutional network could scale on ImageNet.

Try it

AlexNet’s weights are 244 MB, too many for this page. So here is a later, smaller network trained on the same thousand classes: MobileNetV2 (Sandler et al., 2018), with 3.5 million weights. It runs in your browser, on a picture of your choice. The picture never leaves your device.

Name what is in a picture

Interactive
?
pick a picture

    Pick an example, or choose your own picture.

    Next

    AlexNet has eight layers that learn. Later networks have a hundred. What happens when we keep adding layers? That is going deeper.


    Sources: Sandler, Howard, Zhu, Zhmoginov and Chen, “MobileNetV2: Inverted Residuals and Linear Bottlenecks” (2018), run with ONNX Runtime Web from the ONNX Model Zoo’s converted model; Krizhevsky, Sutskever and Hinton, “ImageNet Classification with Deep Convolutional Neural Networks” (2012); Deng et al., “ImageNet: A large-scale hierarchical image database” (2009). AlexNet’s sizes are worked out from the reference network’s layer list (in the original, convolutions 2, 4 and 5 each saw half of the previous maps, because the network was split across two graphics cards). The colour picture is drawn by code.

    ← Browse all subjectsBack to the beginning ↑