What YOLOv8 Does
YOLO (You Only Look Once) detects objects in images in a single forward pass — no sliding windows, no region proposals. YOLOv8 by Ultralytics is the latest iteration: faster, more accurate, and dead simple to use in Python.
You give it an image, it returns bounding boxes with class labels and confidence scores. Works on images, video streams, and webcams out of the box.
Install and Run in 60 Seconds
| |
| |
That’s it. Three lines to go from nothing to object detection. The yolov8n.pt model is the smallest (6.3MB) and runs in real-time even on a CPU.
Understanding the Results
The results object contains everything you need — bounding boxes, class names, confidence scores.
| |
Key properties on each box:
box.xyxy— bounding box as[x1, y1, x2, y2]box.xywh— bounding box as[center_x, center_y, width, height]box.conf— confidence score (0 to 1)box.cls— class ID (maps tomodel.names)
Run on Video
YOLOv8 handles video natively. It processes frame by frame and can write the output to a new video file.
| |
The conf=0.5 parameter filters out detections below 50% confidence, which cuts down on false positives in noisy scenes.
Filter Specific Classes
You don’t always want every object. Filter by class ID to detect only what matters.
| |
Model Sizes
YOLOv8 comes in five sizes. Pick based on your speed/accuracy tradeoff:
| Model | Size | mAP | Speed (CPU) | Use Case |
|---|---|---|---|---|
| yolov8n | 6.3 MB | 37.3 | 80ms | Edge devices, real-time |
| yolov8s | 22.5 MB | 44.9 | 130ms | Balanced |
| yolov8m | 52 MB | 50.2 | 240ms | General purpose |
| yolov8l | 87 MB | 52.9 | 375ms | High accuracy |
| yolov8x | 136 MB | 53.9 | 480ms | Maximum accuracy |
| |
Save Results Programmatically
Export detections to JSON, save annotated images, or draw custom bounding boxes.
| |
Common Issues
CUDA out of memory. Use a smaller model (yolov8n instead of yolov8x) or reduce the input image size with imgsz=640.
Low confidence scores. If detections are weak, the objects might be too small or occluded. Try increasing imgsz to 1280 for better small-object detection.
Wrong classes detected. The pretrained model uses COCO’s 80 classes. If you need to detect custom objects (like specific products or defects), you’ll need to fine-tune on your own dataset.
| |
When to Use What
- Real-time surveillance →
yolov8non GPU, stream mode - Batch image processing →
yolov8moryolov8l, process in batches - Custom objects → Fine-tune any model on your labeled dataset
- Edge deployment → Export to ONNX or TensorRT for optimized inference