C.W.K.
Stream
Lesson 03 of 06 · published

Object Detection: YOLOV8

~9 min · keras-cv

Level 0Keras Apprentice
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

Detection = boxes + labels, not just labels

Classification answers "what's in this image?" Detection answers "what's in it, and where?" — it returns a bounding box and a class for every object it finds, possibly dozens per frame. That's a harder problem, and historically it meant wrestling the TensorFlow Object Detection API or a third-party YOLO repo. KerasCV folds it into the same from_preset idiom you already know.

YOLOV8 is the workhorse here — a single-stage real-time detector that's become the default for production detection. One call loads it with COCO-pretrained weights, and a predict returns a dict of boxes, class IDs, and confidence scores. Non-max suppression (collapsing overlapping boxes of the same object) is handled for you.

Picking a size

YOLOV8 comes in five sizes — xs (fastest), s, m, l, xl (most accurate) — the same latency/accuracy dial as the backbones in the previous lesson. For real-time video on modest hardware, xs/s; for offline batch accuracy, l/xl. To fine-tune on your own classes, freeze the backbone and train just the detection head — that's the next lesson's pipeline.

Code

Load YOLOV8 and run detection inference·python
# Load YOLOV8 with COCO pretrained weights
detector = keras_cv.models.YOLOV8Detector.from_preset(
    "yolo_v8_m_coco",  # xs, s, m, l, xl sizes
)

# Run inference
predictions = detector.predict(images)
# predictions["boxes"] → bounding box coordinates
# predictions["classes"] → class IDs
# predictions["confidence"] → confidence scores

External links

Exercise

Load YOLOv8s pretrained on PASCAL VOC. Run predict on 5 test images and draw the boxes (with class + confidence) using matplotlib or keras_cv.visualization.plot_bounding_box_gallery. Then deliberately drop the confidence threshold and watch false positives appear — note one false positive and one missed detection, and reason about why each happened (occlusion? unusual scale? class not in VOC's 20?).
Hint
VOC only has 20 classes — a 'missed' detection is often an object that simply isn't in the label set. The confidence threshold is the single biggest lever on the precision/recall trade-off; sweep it before touching anything else.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.