YOLO - iffatAGheyas/computer-vision-handbook GitHub Wiki

🧠 YOLOv8 Object Detection — Step-by-Step Guide


📌 What Is YOLO?

YOLO (You Only Look Once) is a real-time, deep learning–based object detection algorithm. It processes the entire image in one pass through a neural network and directly predicts:

  • Bounding boxes
  • Object class labels
  • Confidence scores

YOLO is known for being fast, accurate, and ideal for real-time applications.


🚀 Why YOLOv8?

YOLOv8 is the latest version of YOLO, developed by Ultralytics. It:

  • Supports multiple tasks: detection, segmentation, pose estimation
  • Offers better accuracy and flexibility than previous YOLO versions
  • Comes with ready-to-use APIs — no manual downloads required

⚙️ How YOLOv8 Works

  1. Input Image is resized and normalized
  2. YOLOv8 divides the image into a grid
  3. For each grid cell, it predicts:
    • Multiple bounding boxes
    • Confidence scores
    • Class probabilities
  4. Applies Non-Maximum Suppression to remove overlapping detections

📦 Installation & Setup

Use YOLOv8 in a Jupyter notebook or Python script by installing the Ultralytics package:

# Install the ultralytics package (this downloads YOLOv8 weights too)
!pip install ultralytics

This will automatically download:

  • The yolov8n.pt model (nano version — fast & lightweight)

  • Required dependencies for PyTorch, OpenCV & visualization

🧪 Example Code: Run YOLOv8 on an Image

import cv2
import matplotlib.pyplot as plt
from ultralytics import YOLO

# 1. Load the pre-trained YOLOv8n model (downloads automatically)
model = YOLO('yolov8n.pt')

# 2. Run inference on an image
results = model('bird1.jpg', imgsz=640)

# 3. Render detections on the image
det_img = results[0].plot()

# 4. Convert to RGB and display
det_img = cv2.cvtColor(det_img, cv2.COLOR_BGR2RGB)
plt.figure(figsize=(10, 6))
plt.imshow(det_img)
plt.axis('off')
plt.title('YOLOv8 Object Detection')
plt.show()

Example output: a bounding box around each detected object with class label and confidence score.

🖼️ What You’ll See

  • YOLOv8 will detect the object(s) in your image (e.g., bird)

  • A bounding box with a label and confidence score, e.g.:

bird 0.93
  • The image will look something like this image

imageKey Benefits

Feature Why It Matters
Deep Learning Learns rich object features
Real-time Speed Suitable for video streams and live cameras
Pretrained Models Works out-of-the-box on 80 COCO classes
Multi-class Detects birds, cars, people, and more