Machine Learning Basics

How Computers Recognize Images

A walkthrough of how software learns to label what appears in a photo, from pixels and edges to trained models, plus why it still gets things wrong.

On this page
  1. A photo is a grid of numbers
  2. Why fixed rules fall short
  3. Learning from labeled photos
  4. Building up from simple to complex patterns
  5. Different jobs, same family
  6. Where errors come from
  7. Judging a system fairly
  8. Putting it together

A photo is a grid of numbers

To a person, a photo of a dog is obviously a dog. To a computer, it begins as a grid of tiny colored squares called pixels. Each pixel is stored as a few numbers describing how much red, green and blue it contains. A small phone photo can hold millions of pixels, so the raw input is millions of numbers with no label attached.

The task of image recognition is to turn that grid into something meaningful, such as “dog,” “stop sign” or “damaged package.” There is no obvious formula for this, which is why it became a showcase for machine learning.

Why fixed rules fall short

Early approaches tried to describe objects by hand: look for pointed ears, four legs, a certain texture. These rules were brittle. Dogs come in many shapes, photos are taken from many angles, and lighting changes every pixel value. Hand-written rules also tend to grow endlessly as exceptions appear.

The modern approach is to show a program many labeled photos and let it discover which patterns matter.

Learning from labeled photos

A typical setup looks like this.

  1. People collect a large set of images and attach labels, such as which objects each one contains.
  2. A model is given an image and produces a guess, often as a list of scores, one per possible label.
  3. The guess is compared with the correct label, and the model’s internal settings are adjusted to reduce the error.
  4. This repeats across many images, many times.

This is an example of learning from labeled examples, an approach called supervised learning. The quality and variety of the photos matter a great deal, because the model can only learn what the examples show.

Building up from simple to complex patterns

Most modern systems use a type of neural network designed for images. You can picture it as a series of stages.

  • Early stages respond to simple local patterns, such as edges, corners and patches of color.
  • Middle stages combine those into textures and parts, such as a curve that might be an eye or a wheel.
  • Later stages combine parts into whole objects and produce the final scores.

A key trick is that the same small detector slides across the whole image, so a pattern can be spotted wherever it appears. The model is not told to look for edges first. Training tends to produce this layered behavior on its own, which is why layered designs are so popular. Such layered models belong to the family of neural networks, built from many adjustable weights.

Different jobs, same family

“Recognizing an image” can mean several tasks.

  • Classification assigns one label to the whole picture.
  • Detection finds objects and marks where they are, often with boxes.
  • Segmentation labels each pixel, such as road versus sidewalk.
  • Matching compares one image to others, which is the idea behind some forms of facial recognition and the pictures used in self-driving technology.

Each has different data needs. Detection and segmentation require more detailed labels, which are costly for people to produce.

Where errors come from

Image models can be impressive and still surprise their users. Common causes of mistakes include:

  • Unfamiliar conditions. A model trained mostly on daytime photos may struggle at night.
  • Shortcuts. A model might learn that a background, such as snow, predicts a label, rather than the object itself. When the background changes, it fails.
  • Imbalanced examples. Rare objects are often missed because the model saw few of them.
  • Tiny changes. Researchers have shown that carefully altered pixels, sometimes invisible to people, can make a model change its answer.
  • Poor labels. If people labeled some images incorrectly, the model learns the mistakes.

Uneven coverage in the photos can also lead to unequal results across groups of people, a concern discussed under algorithmic bias.

Judging a system fairly

When a company says its software recognizes images with a high accuracy rate, it helps to ask what the test photos were, whether they resemble real conditions, and how mistakes are handled. A result on a tidy benchmark does not automatically carry over to messy real-world pictures.

Putting it together

Image recognition is pattern learning at a large scale. Software turns pixels into increasingly abstract features, then compares the result with labels it learned from examples. It can be very useful for sorting photos, reading documents or helping inspect products. But it works from resemblance to its training pictures rather than understanding, which is why unusual cases and thoughtful testing deserve attention.

The complete guide to machine learning basics

Machine Learning Explained for Beginners
Read the guide

Keep exploring

Guides from other topics

All topics →