Home›Part 3 Deep Learning & AI›3.4

Part 3 · Deep Learning & AI

3.4 Object detection and segmentation

Answering “what is where”

10-minute readPrerequisites: 3.3 CNNs and image recognition, 2.7 Evaluation metrics▶ Video (about 5 min)

What you will learn

  • Explain the difference between image classification, object detection and segmentation, together with their uses in automated driving
  • Calculate IoU, which measures how well boxes overlap, and explain how NMS removes duplicate boxes
  • Explain how detection is evaluated (IoU criteria, precision and recall, AP) and the pitfalls with small distant objects, occluded objects and objects side by side

Build intuition

The image classification of 3.3 answers “this image contains a pedestrian”. Driving, however, needs to know what is where, and how many: “one pedestrian ahead on the left, two cars in the right lane”. Several kinds of task serve this purpose:

TaskWhat it answersExample in automated driving
Image classificationOne category for the whole imageWhich sign a cropped sign image shows
Object detectionA box (position and size), category and confidence for each objectFinding pedestrians, cyclists and cars
Semantic segmentationA category for every pixelRoad, sidewalk, lane markings — where the car can drive
Instance segmentationA category for every pixel, plus which individual object it belongs toSeparating overlapping pedestrians one by one
Detection: draw boxes Segmentation: color every pixel car 0.97 pedestrian 0.88 box, category and confidence road car pedestrian
Two ways of answering for the same scene (schematic). Object detection gives each object a box, a category and a confidence; segmentation gives every pixel a category.

An object detection model picks up features with a CNN (3.3) or similar, then predicts, all at once for many positions and sizes across the image, “is there an object here, what is it, and how should the box be adjusted?”. This produces many slightly shifted candidate boxes for the same object. So the most confident boxes are kept, duplicates are removed, and only those above the threshold (2.4) become the answer.

Check with math

① IoU: how well a box fits

IoU (introduced in 2.7) expresses how much a predicted box A overlaps the true box B: the area of the overlap divided by the area they cover together.

$$\mathrm{IoU} = \frac{|A \cap B|}{|A \cup B|}$$

∩ is the overlap, ∪ is the combined region, and | | means area (see Notation). A perfect match gives 1; no overlap at all gives 0. Many evaluations count a detection as correct when IoU is at least 0.5.

Nearby pedestrian (100×200 px) Distant pedestrian (10×28 px, shown 3×) IoU = 14,400 ÷ 25,600 ≈ 0.56 shifted 20 px each way, ≥ 0.5 → correct detection IoU = 168 ÷ 392 ≈ 0.43 shifted just 4 px, < 0.5 → fails dotted: true box · solid: predicted box · shaded: overlap
The smaller the object, the more a slight shift lowers IoU. For a distant pedestrian, a few pixels of error are enough to fall below the “correct detection” criterion.

On the left, the overlap is 80 × 180 = 14,400 and the combined area is 20,000 + 20,000 − 14,400 = 25,600, so IoU ≈ 0.56. On the right, the overlap is 6 × 28 = 168 and the combined area is 280 + 280 − 168 = 392, so IoU ≈ 0.43.

② What a detector outputs, and how it learns

For each object, a detector outputs the box’s position and size (x, y, width, height), a probability for each category, and a confidence. The training loss adds the box error (regression, as in 2.2) to the category error (the cross-entropy of 2.4). In other words, it solves regression and classification at the same time.

③ NMS: removing duplicate boxes

The standard procedure for removing duplicate boxes for the same object is NMS (non-maximum suppression):

  1. Pick the box with the highest confidence and keep it as an answer
  2. Remove boxes whose IoU with that box exceeds a threshold (for example 0.5), treating them as duplicates of the same object
  3. Repeat steps 1–2 with the remaining boxes

This procedure becomes a weakness when boxes of different objects overlap heavily. If the boxes of two pedestrians walking side by side have an IoU of 0.6, NMS with a threshold of 0.5 removes one of them as a “duplicate”.

④ Evaluating detection: AP

For evaluation, predicted boxes are sorted by confidence; those matched to a true box with IoU at or above the criterion count as correct detections, the rest as false alarms, and true boxes with no matching prediction as misses (the confusion matrix of 2.7). Computing precision and recall while moving the threshold gives a curve whose area is the AP (average precision); the mean of the APs across categories is the mAP. For segmentation, the mean IoU across categories (mIoU) is commonly used.

Connection to automated driving

  • Detections feed the next stages: detected boxes are passed on to tracking, motion prediction and path planning. A miss in a single frame can sometimes be bridged by tracking, but repeatedly missing the same object throws off every decision downstream. → 4.2 System overview, 4.5 Prediction and motion planning
  • Misses that are close and in the path matter most: AP counts missing a distant parked car and missing the pedestrian right in front as one miss each. One approach is to evaluate separately by distance and relevance to the path, or to use metrics weighted by the impact on driving decisions.
  • Small, occluded, side by side: small distant objects easily fall below the IoU criterion, and pedestrians half hidden behind parked cars or walking together are easily dropped by detection or by NMS. Check performance separately by size, occlusion level and crowding. → 5.3 Functional insufficiencies and triggering conditions
  • Box accuracy matters for safety too: in camera images, the distance to an object is sometimes estimated from, for example, the position of the bottom of its box. The further away, the larger the distance error from a single pixel of error — which affects when to brake.
  • The same ideas apply to LiDAR: from LiDAR point clouds, objects are detected as 3D boxes (position, size and heading), and evaluation uses 3D IoU. → 4.3 Sensors and fusion

Summary

  • Object detection gives each object a box, a category and a confidence; segmentation gives every pixel a category. Driving needs “what, where and how many”
  • Box fit is measured by IoU (overlap ÷ combined area), and duplicate boxes are removed by NMS. Detection is evaluated with precision and recall based on an IoU criterion, and with AP
  • Small objects can fail the criterion with a few pixels of error, and objects side by side can vanish in NMS. Evaluate separately by distance, path relevance, size and occlusion

Quick quiz

Q1. A true box and a predicted box overlap by 14,400, and together cover 25,600. What is the IoU? With a criterion of 0.5, is it a correct detection?

IoU = 14,400 ÷ 25,600 ≈ 0.56, which is at least 0.5, so it counts as a correct detection.

Q2. For a distant pedestrian 28 pixels tall and 10 wide, the predicted box (the same size) is shifted 4 pixels sideways. What is the IoU?

The overlap is 6 × 28 = 168 and the combined area 280 + 280 − 168 = 392, so IoU ≈ 0.43. With a 0.5 criterion, this prediction counts as a false alarm and the true pedestrian as a miss.

Q3. Two pedestrians walk side by side, and their boxes have an IoU of 0.6. What can happen with an NMS threshold of 0.5?

The less confident box is treated as a “duplicate of the same object” and removed, so it can look as if there is only one person (a miss). Crowded scenes need to be checked, including the NMS threshold.

Q4. What are the names of the task that colors every pixel as “road, sidewalk, lane marking, car”, and the task that also separates overlapping pedestrians one by one?

The first is semantic segmentation; the second is instance segmentation.

Further reading