CSC3104 · Module 5 of 9

Object Detection

Find object classes & locations

~56 min to study properly

Classification asks ‘what is in the image?’ Detection asks ‘what, and where?’ — for every object it outputs a class, a confidence score, and a bounding box (x, y, width, height).

Checkpoint · the examiner asks

Walk me through how Non-Maximum Suppression (NMS) works, and explain why it is necessary in object detection.

In one minute

Detection outputs class + confidence + box for every object. Two-stage detectors (Faster R-CNN) propose regions then refine them; one-stage detectors (YOLO) predict on a grid in one pass for real-time speed. IoU measures box overlap; NMS keeps the best box and removes overlapping duplicates above an IoU threshold; mAP evaluates the whole detector.

Traps examiners look for
  • Computing IoU as intersection over the sum of areas (forgetting to subtract the intersection).
  • Running NMS across different classes when it should be per class.
  • Setting the NMS IoU threshold so low that neighbouring objects get suppressed.
Read

Study notes

01From "what" to "what and where"

Classification outputs one label per image. Object detection outputs a list of objects, each with:

  • a class ("car", "person"),
  • a confidence score (0–1),
  • a bounding box, as (x1, y1, x2, y2) corners or (x, y, w, h).

Detectors are trained with two losses at once: a classification loss for each predicted box and a regression loss (e.g. smooth L1 or IoU-based) for the box coordinates. Many detectors predict boxes relative to predefined anchor boxes of several shapes and sizes placed across the image.

02Two-stage vs one-stage detectors

Two-stage (Faster R-CNN)One-stage (YOLO, SSD, RetinaNet)
How1) a Region Proposal Network suggests ~hundreds of candidate regions; 2) each is classified and its box refinedpredicts classes and boxes for every grid cell / anchor in one pass
Speedslowerfast — real-time video
Accuracytraditionally higher, especially small objectsclose or equal in modern versions

One-stage detectors face extreme class imbalance: most of tens of thousands of anchors are background. Focal loss (RetinaNet) down-weights easy, well-classified examples so training focuses on the hard ones: FL = −(1 − p)^γ log p.

03IoU and Non-Maximum Suppression

Intersection over Union measures how much two boxes overlap:

IoU = area(A ∩ B) / area(A ∪ B), with area(A ∪ B) = area(A) + area(B) − area(A ∩ B).

1 means identical boxes; 0 means no overlap. A prediction usually counts as correct if IoU with a ground-truth box ≥ 0.5.

Detectors fire many overlapping boxes on the same object. Non-Maximum Suppression (NMS) cleans them up, per class:

  1. Drop boxes below a confidence threshold.
  2. Sort the rest by confidence.
  3. Keep the highest; remove every remaining box whose IoU with it exceeds the NMS threshold (e.g. 0.5).
  4. Repeat with the next highest remaining box.

A low NMS threshold suppresses aggressively (can delete a genuine neighbouring object in a crowd); a high one leaves duplicates.

04Evaluating with mAP

Detection is evaluated with mean Average Precision (mAP):

  1. For one class, sort all predictions by confidence. Walk down the list, marking each as TP (matches an unmatched ground-truth box with IoU ≥ threshold) or FP.
  2. This gives a precision–recall curve; AP is the area under it.
  3. mAP averages AP over classes.

Report the IoU threshold: mAP@0.5 (PASCAL VOC style) is lenient; mAP@[.5:.95] (COCO) averages over IoU thresholds 0.5 to 0.95 and rewards precise localisation. A model can have good mAP@0.5 but poor COCO mAP if its boxes are sloppy.

Watch it done

Worked examples

Worked example 1

IoU of two boxes

Box A = (10, 10, 50, 50) and Box B = (30, 20, 70, 60), as (x1, y1, x2, y2). Compute IoU.

    Worked example 2

    NMS by hand

    Three 'car' boxes: A (0.95), B (0.80, IoU with A = 0.72), C (0.60, IoU with A = 0.10, IoU with B = 0.15). NMS threshold 0.5. Which survive?

      Vocabulary

      Key terms

      Detectors that skip NMS

      DETR (2020) treated detection as set prediction with Hungarian matching — no NMS needed. YOLOv10 (2024) brought NMS-free training to YOLO with consistent dual assignments, and Ultralytics' YOLO26 continues the end-to-end, NMS-free design for faster, more predictable edge deployment.

      Practise

      Quick check

      0 of 8 correct so far. Wrong answers come with an explanation — and the buddy can unpack them.

      Q1Box A and B are both 10×10 and overlap in a 5×10 strip. IoU?

      Q2Raising the NMS IoU threshold from 0.3 to 0.8 will…

      Q3A predicted box and a ground-truth box have IoU = 0.62. With the usual threshold, is it a correct detection?

      Q4What does the Region Proposal Network do in Faster R-CNN?

      Q5Why was focal loss introduced?

      Q6Lowering the NMS IoU threshold from 0.7 to 0.3 tends to…

      Q7mAP@[.5:.95] differs from mAP@0.5 by…

      Q8For real-time video on an edge camera, which detector family is the usual choice?

      Exam-style

      Written practice

      Short answer6 marks

      Define IoU and explain Non-Maximum Suppression step by step.

      Short answer5 marks

      Compare two-stage and one-stage object detectors.

      Long answer12 marks

      You must count vehicles at a busy Kampala junction from a roadside camera in real time. Choose a detector, explain how you'd train and tune it (including NMS and confidence thresholds), and how you'd evaluate it, noting the challenges of crowded scenes.

      Watch

      Videos

      Fresh picks are chosen by AI every day.
      Hands-on

      IoU & NMS simulator

      4 guided tasks: predict, experiment, explain — then challenge yourself. Plus 2 coding exercises you run right in the browser.

      Start the lab
      Transfer LearningSegmentation