AI Hints
Home›Computer Vision Tutorial›Object Detection
Computer Vision · Lesson 19 of 111

Running YOLO

A real detector in practice.

⏱ 2 min read▶ Video at 31:57🎓 Free
Watch this lesson in the Computer Vision courseWatch on YouTube ↗Full Computer Vision course

YOLO has gone through many versions, and today, it's a single pip install away. It's fast enough for live video, on a normal laptop. Let's see what it gives you, and how to control it.

Running YOLO
From the video: Running YOLO
  • Many versions
  • One pip install
  • Fast enough for live video

Using YOLO

We load the nano version, the smallest one. Conf sets the minimum confidence, and I o U sets the NMS threshold. Those are the two dials that you'll tune the most. Run it. It takes a fraction of a second, even without a GPU. It has about two and a half million weights, and it knows eighty kinds of object. Each result has a class, a box, and a score. But it doesn't know apples from bruises. For that, we need our own training data.

yolo.pypython
from ultralytics import YOLO
from skimage import data
import cv2
import time

model = YOLO("yolo11n.pt")
image = cv2.cvtColor(data.coffee(), cv2.COLOR_RGB2BGR)

start = time.time()
result = model(image, conf=0.25, iou=0.5, verbose=False)[0]
print(f"Time: {time.time() - start:.2f}s")

print("Weights:", sum(p.numel() for p in model.model.parameters()))
print("Knows", len(model.names), "kinds of object")
for b in result.boxes:
    print(model.names[int(b.cls)], [int(v) for v in b.xyxy[0]], round(float(b.conf), 2))
Output
Time: 0.72s
Weights: 2624080
Knows 80 kinds of object
cup [170, 17, 421, 316] 0.82
dining table [9, 1, 597, 399] 0.78
spoon [324, 215, 406, 328] 0.29

Summary

Two dials, conf and I o U, control what you get. Now let's teach it something new. The next step is preparing a dataset, and it's where most real projects are won or lost.

Key takeaways
  • conf and iou are your dials
  • Nano is small and fast
  • COCO has 80 classes
Next up: Training on Your Own Data — labels, formats, and YOLO