01

Measuring fruit with a camera

Farms and packing houses use cameras to measure fruit, sorting it by size and shape. A computer vision model draws an outline around each fruit in an image and calculates its area. From this, it can estimate size or weight. The accuracy of the outline is therefore important.

02

The shadow problem

When a pear sits on a surface under a lamp, it casts a shadow. On a light background, the shadow may be dark and sharp, touching the edge of the fruit. A model might include part of the shadow in its outline, making the pear appear larger than it really is.

03

Labelling the real fruit

To train the model, people mark the boundary of the physical pear in each image, excluding the shadow. They label several views of the same pear, from different angles and with different backgrounds. This teaches the model where the fruit truly ends.

04

Light and dark surfaces

A shadow is easier to separate from a pear on some surfaces than others. On a dark surface, the shadow may barely show; on a white surface, it may be very strong. Testing on both kinds of background shows whether the model performs consistently.

05

Change one thing at a time

To find out whether the shadow is causing errors, a careful test changes only one factor. Keep the pear, camera and background exactly in place, and move or rotate the light. The pear does not change, but its shadow moves to a different side.

06

Reading the result

If the predicted outline changes shape and moves with the shadow, the model is including the shadow as part of the fruit. If the outline stays the same, the model has learned to ignore the shadow. Comparing the outlines measures how much the shadow affects the result.

07

Why not change everything?

If the test changed the light, background and pear all at once, it would be impossible to know which change caused any difference in the outline. Controlled tests, changing one factor at a time, are a basic principle of experiments in science and engineering.

08

Measuring the error

The difference between the predicted area and the labelled area can be expressed as a percentage. A consistent overestimate when shadows are strong reveals a systematic error, which might lead to pears being placed in the wrong size category.

09

Improving the system

Solutions include adding more training images with strong shadows, using diffuse lighting that reduces shadows, placing several lights around the fruit, or using a background colour that makes shadows easier to tell apart from the pear.

10

Testing what matters

Frameworks such as NIST's AI Risk Management Framework encourage developers to identify the conditions that could cause an AI system to fail, and to test for them deliberately. Shadows are one such condition for a fruit-measuring camera.

11

Pears around the world

About 3,000 varieties of pear are grown worldwide, in many shapes, from round to long-necked, and colours from green to yellow and red. A model trained on one variety may outline others less accurately, so a test set should include the shapes and colours it will meet in use. China grows the large majority of the world's pears.

12

Cameras on the packing line

On a real packing line, fruit moves quickly on conveyors, so cameras take pictures in fractions of a second. Lighting inside the machine can be designed to reduce shadows, making outlines easier to measure.

13

Try the arithmetic

If a pear's true outline covers 50 square centimetres in an image and the model's outline covers 58, the shadow has caused an overestimate of 8 square centimetres, or 16 per cent.

14

The idea to take away

An automatic outline can include a pear's shadow and overestimate its size. Label the real fruit boundary, then test the same pear while moving only the light. If the outline follows the shadow, the model has confused the two.

FOLLOW THE EVIDENCE

Sources & further reading

Figures in the example are illustrative. Photograph: Pear DS.jpg by Augustus Binu : flickr, CC BY-SA 3.0, via Wikimedia Commons; cropped and resized. Reference organisations do not endorse this website.