Theory
Object detection answers two questions for every object in an image: what it is (classification) and where it is (a bounding box). Two families of detectors exist:
- Two-stage detectors such as Faster R-CNN first propose candidate regions, then classify each one. They are accurate but slower.
- One-stage detectors such as YOLO and SSD predict boxes and classes directly in a single pass of the network.
YOLO (You Only Look Once, Redmon et al., 2016) framed detection as one regression problem over the whole image, which made real-time detection practical.
YOLOv8
YOLOv8 (Ultralytics, 2023) has three parts:
- a backbone of convolutional blocks that extracts features,
- a neck that fuses features from different depths so both small and large objects are represented,
- an anchor-free, decoupled head that predicts box geometry and class scores separately at three strides (8, 16 and 32 pixels).
For a 640 × 640 input that gives 80 × 80 + 40 × 40 + 20 × 20 = 8400 candidate positions. The output tensor has shape [1, 84, 8400]: for each candidate, four box values (center x, center y, width, height) and 80 class scores for the COCO dataset.
The nano model YOLOv8n has about 3.2 million parameters, small enough to run in a web browser.
From image to detections
- Letterbox the image: resize it to fit 640 × 640 while keeping its aspect ratio, and pad the rest with gray.
- Scale pixel values to 0 to 1 and reorder from height × width × channel to channel × height × width.
- Run the network.
- For each candidate take the highest class score; discard candidates below the confidence threshold.
- Convert boxes to corner coordinates and undo the letterbox scaling.
- Apply non-maximum suppression: among overlapping boxes of the same class keep the most confident, removing any whose IoU with it exceeds a threshold.
IoU (intersection over union) = area(A ∩ B) / area(A ∪ B). Detectors are evaluated with precision, recall and mAP, the mean of average precision over classes.
Workbench
Run YOLOv8n in the browser on images, a video file or the webcam.
Input
Input preview
Parameters
Readout
- n/a
- n/a
Export
Procedure
- Load Street at dusk and run detection with a confidence threshold of 0.25 and an IoU threshold of 0.45.
- Record each detection's class, confidence and box in a table.
- Raise the confidence threshold to 0.5 and 0.75 and note which detections disappear.
- Lower the IoU threshold to 0.2 and raise it to 0.8, and observe duplicate boxes.
- Run detection on three of your own photographs with different object types.
- Load a short video file, then start the webcam, and record the frames per second.
- Note one false positive and one missed object, and explain likely causes.
- Save annotated figures for the report.
Results and Discussion
To be completed
Add your detection tables and figures: how the thresholds changed the results, the frame rate you measured, and the failure cases you found.
Conclusion
To be completed
Summarize how a one-stage detector like YOLOv8 works and where it struggles, in your own words.