In this lesson
Machines learn to see from examples.
A phone recognizes its owner's face, and a store camera counts who walks in. Behind both is computer vision. Here you see how it works and when it is worth training a model with your own photos.
- Choose between classifying, detecting and segmenting
- Know when to train with your own photos
- Read the metrics without fooling yourself
Why it needs examples
A machine does not know what a car is. It knows what someone showed it. A person writes down the name of what appears in thousands of photos. That annotation is called a label, and the network learns to link pixel patterns to the labels. That is why a model only knows the categories it was trained on.
And the network does not say "I have never seen this". A new object gets the closest category, often with high confidence.
Three questions, three tasks
| Task | Question it answers | Data preparation |
|---|---|---|
| Classification | What is this image? | One label per photo |
| Detection | What is here, and where? | One box drawn per object |
| Segmentation | Which pixels belong to the object? | An exact outline, the most expensive |
Use the simplest task that answers the question. If all you need to know is whether there is a hard hat, classification does the job.
Start with a ready-made detector
Many projects start with a detector trained on COCO, a reference dataset with 80 common categories, such as person, car and bottle. Before you label a single photo, run it on 20 images from your own setting and sort them into three piles: what it gets right, what it gets wrong and what it does not even try, because the category is not among the 80.
In video, the detector runs on every frame. A person standing still in front of the camera is counted on every frame. Counting detections is not counting people: for that you need tracking.
Training with your own photos
When the category does not exist in COCO, train. Starting from a ready-made model is much cheaper, because the network already knows edges and textures. A few hundred examples per class are usually enough to get started.
Watch the validation. If you photographed the same box 30 times in a row and drew 20% of the photos at random, the validation set is made of near copies of the training set, and the number comes out pretty and false. Split by capture session: day, place and device.
What the pros know
Two numbers look the same and say different things. According to Ultralytics, the mAP50 counts a detection as a hit when the box overlaps the hand-drawn box by at least 50%: only the easy cases. The mAP50-95, in turn, averages thresholds from 50% to 95%, which demands tight boxes. If the mAP50 is high and the mAP50-95 is low, the model finds the object but draws a loose box. For counting, that may be enough. For measuring size or position, it is not.
Reading the metrics
Precision tells you how many detections are real, that is, how much the model makes up. Recall tells you how many real objects were found, that is, how much it lets slip by. Raising the confidence threshold increases precision and brings recall down. The cost of each error decides the point: a false alarm for a missing hard hat costs a glance, and a hard hat that goes undetected can cost a life.
The confusion matrix shows which class turns into which class. If one row leaks into another, the two are too much alike. Both cases point to the data, not to the model.
Careful
The LGPD, Brazil's data protection law, treats biometric data linked to a person as sensitive personal data. Detecting "there is a person" is enough for counting. Recognizing who each one is requires a legal basis of its own. When you do not need the recorded face, blur it before you store it.
Practice · 5 min
- Run the ready-made detector on 20 photos from your own setting and sort them: gets it right, gets it wrong and category that does not exist.
- For the errors, note whether they look like low confidence, a duplicate box or a small object.
- Write in three lines where your validation would come from and what cannot be on both sides.
Summary
- The model only knows what was labeled, and it does not warn you when it does not know.
- Use the simplest task that answers the question.
- Split the validation by session, never by a random draw of similar photos.
- Compare mAP50 with mAP50-95 and read the confusion matrix.
Sources
Read on October 30, 2026.
- Ultralytics. YOLO Performance Metrics: IoU, mAP50 and mAP50-95.
- Ultralytics. Predict: detector parameters.
- Brazil. Lei 13.709/2018 (LGPD): biometric data and purpose.
Lesson quiz
Three situations to apply what you learned.
Isaque Victor free courses