Go to Map Courses Lab Glossary How it works Troubleshooting Start →
ITEN
← Course 02 · Seeing (Lesson 02.04 · 16 minutes · Camera · First model)

Cutting out pixel by pixel.

A spot on a leaf doesn't fit in a box. Here a model gives an answer for every pixel, separates people from the background in video calls, and estimates how far away each point of a photo is.

What you learn
  1. What a mask is and how you use it to measure
  2. Why the networks that segment are shaped like a U
  3. The difference between semantic and instance segmentation
  4. How a model estimates depth from a single photo
You need to know

If you don't remember one of these, the link takes you to the chapter that explains it.

How do you want to follow it
Preparing the scene…
  1. 01 Every pixel

    Every pixel gets its own class.

    A spot on a leaf is not a box. To measure it, you need to know which pixels are spot and which aren't. That's exactly what segmentation01.04 does. It gives a class to every pixel of the photo, for example leaf, spot or background. The result is a second image, the same size as the first, made of colored areas.

    In practice. Segmentation is for when the shape or the area matters. If you only need to know where an object is, a box costs much less.

01 / 07
(Go deeper)

A few more numbers.


(01)

U-Net, made for the microscope

Olaf Ronneberger and two colleagues at the University of Freiburg presented U-Net in 2015. It was built to segment cells under the microscope, where labeled photos are very few. In one of the contests it won, it had only 30 images to learn from.

The secret is the bridges, called skip connections. They copy the fine details from the first half of the network, before they get lost, and hand them to the second half right where they're needed to draw the edges. Since then the U shape shows up everywhere, even inside many models that generate images.

(02)

How you measure a mask

For masks you use the same IoU02.03 as for boxes, counting pixels instead of areas. You compare the model's mask with the one drawn by hand, pixels in common divided by pixels covered in total.

In medicine people often use the Dice coefficient too. It counts the pixels in common twice and divides them by the sum of the pixels in the two masks. It goes from 0 to 1 like IoU and is always a bit higher for the same masks, so only compare two numbers of the same kind.

IoU  = pixels in common / pixels covered in total
Dice = 2 × pixels in common / (pixels in mask A + pixels in mask B)
(03)

Relative depth and real meters

Depth Anything V2, published in 2024, comes in three sizes. The smallest has about 25 million weights, the largest 335 million. Out of the box it gives a relative depth. It knows the vase is closer than the window, but not that it's 80 centimeters away.

To get meters you need more information, like the size of the sensor and the focal length, or a model trained on purpose with photos where the distances were measured. That's what the metric versions of the same model do, and Apple's Depth Pro too.

  • 25 Mweights in the Small version
  • 335 Mweights in the Large version
(Try it on your phone)

Live segmentation


Use the front camera and point it at yourself. The model separates the person from the background live, and the background goes dark. With the buttons under the camera view you can see only the mask, or blur the background like in a video call. With the slider you change the confidence threshold and watch how the edges change, especially around your hair and fingers.

The tool needs JavaScript turned on.

Try with the light behind you and then with the light in front of you. The model is the same, the mask isn't. The images stay on your phone.

(Quiz)

4 questions to close the lesson.

When you have answered them all, the lesson counts as done and its stone on the map turns yellow. Answering is what counts, not the score.


  1. (01)

    You want to know how much of a leaf is sick, as a percentage. What do you use?

  2. (02)

    What are the bridges between the two halves of a U-Net for?

  3. (03)

    Three apples are touching. What does semantic segmentation do?

  4. (04)

    What can't a depth model know from a single photo?

To close the lesson, answer the quiz

← Finding objects Back to the map
(Next lesson · 02.05) Hands, body, face