Image classification (CNN)

How a CNN Recognizes Whether an Image Shows a Car, a Truck, or a Bus: Image Classification

Image classification with a convolutional neural network, from pixel through three convolutional stages to the class.

Image classification assigns exactly one class to an entire image. This page works through a trained convolutional neural network (CNN) with 16,043 parameters on image crops of vehicles. A CNN recognizes patterns in images by sliding small filters across the pixels. You pick a spot in the image and see in matrices of numbers how pixel values turn, layer by layer, into the decision for car, truck, or bus.

CNN · trained 16,043 parameters 3 convolutional stages Softmax Car, truck, bus

Choose an image crop at the top. Click in the image to set the spot whose numbers the matrices show. Press “Play” and the computation runs by itself, or use the step list to jump to any point.

All computations run in your browser. Teaching example, not a production forecast.

What the Walkthrough Shows and Where It Ends

The network has three convolutional stages. Each stage slides learned filters across its input, sets negative results to zero (ReLU), and then halves width and height with max pooling. The crop of 64 × 64 pixels thus becomes 32 maps of 8 × 8 values. A final layer combines these 2,048 values into three raw values, and the softmax function turns them into probabilities for car, truck, and bus. Your browser carries out the calculation steps on this page with the trained weights.

The network was trained with PyTorch in 4,000 steps on 3,087 crops from 888 street scenes. The class of each vehicle comes from the predictions of a large detection network, which were cleaned up after a review. On this page, this target class is called the label. The vehicles were not labeled individually by a person. Vans count as trucks, and pickups count as cars.

The measurement used 84 additional scenes that were held out of every training run. Of 300 crops from those scenes, the network assigns 293 the same class as the label. Only the network shown was measured on these scenes. No network was chosen from several candidates after this measurement. The twelve crops on this page were selected because the network classifies them correctly.

This page is a teaching example, not a production system. Only synthetically generated street scenes seen at an oblique angle have been tested. What the network does with photos from the real world, with vertical top-down views, or with other vehicle types has not been measured. The walkthroughs for object detection and semantic segmentation show how a network finds several vehicles in a scene or classifies each pixel individually.