Model cars in images (segmentation)

How a Neural Network Assigns Every Pixel to a Car or the Background: CNN

A convolutional neural network for image segmentation, from pixel through filters and feature maps to the mask.

A convolutional neural network (CNN) recognizes patterns in images by sliding small filters across the pixels. This page works through a trained network with 28,785 parameters on images of model cars. You pick a spot in the image and see in large matrices of numbers how pixel values turn, layer by layer, into the decision “car” or “background.”

U-Net with 28,785 parameters 3 × 3 convolution Max pooling Skip connections Segmentation

Choose a scene, the task, and the threshold 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 is a small U-Net. Three convolutional layers condense the image and halve the resolution twice along the way. Two more rebuild the full resolution and use the early feature maps through skip connections to do so. Your browser carries out the calculation steps on this page with the trained weights on the downscaled image of 320 × 180 pixels. The training metrics come from the training run.

The network was trained with PyTorch in 6,000 steps with AdamW, on eight random 96 × 96 pixel crops per step. Saturation, color cast, contrast, and brightness vary at random, and the crops are flipped at random. About one in four examples is converted to grayscale so that the network does not rely on color. The objective combines binary cross-entropy with half a soft Dice loss. Between neighboring vehicles, a separating band of up to seven pixels per side counts as background and is weighted eight times as heavily in the cross-entropy, so that vehicles that touch form separate groups.

Fifteen scenes were used for training, and five were held out. The width and weight of the separating band and the number of steps were, however, tuned on those five scenes. The reference masks come from roughly placed rectangles that the GrabCut method refined. They have not been checked by hand.

This page is a teaching example, not a production system. Objects are formed here from connected groups of pixels rather than by a dedicated detector such as YOLO or Mask R-CNN, so vehicles that touch can merge into one group. The value per group is the mean pixel probability, not a calibrated confidence. The held-out scenes resemble the training scenes, so the metrics do not demonstrate generalization to other images. All images come from a synthetically generated dataset. What the network does with photos from the real world has not been measured. In a spot check on six more images from the same dataset without a reference mask, the network also marked cubes and screws, and it treated a black conveyor belt entirely as a vehicle. The network therefore separates light backgrounds from everything else and does not recognize vehicles as a class of their own. The walkthroughs for image classification, object detection, and semantic segmentation show how networks assign an image to a class, find vehicles with boxes, or distinguish several classes per pixel.