Drone YOLO Object Detection π¦π©οΈ This repository contains a full pipeline for training a YOLOv8 model on custom drone footage data for object detection and line-crossing analysis. The implementation uses the Ultralytics YOLOv8 framework and is tailored for lightweight and fast inference using the YOLOv8 Nano variant.
π§ Project Overview This project trains a YOLOv8 model to detect objects from drone footage. The detections can later be used for advanced tasks like object counting, trajectory tracking, and boundary-line crossing analytics.
π Directory Structure
The dataset is organized as per the YOLO format. Below is the visual layout:
drone_yolo_dataset/ βββ train/ β βββ images/ β Training images β βββ labels/ β Corresponding YOLO labels βββ val/ β βββ images/ β Validation images β βββ labels/ β Corresponding YOLO labels βββ test/ β βββ images/ β Test images β βββ labels/ β Corresponding YOLO labels data.yaml β Configuration file linking datasets and class names π data.yaml Configuration This file defines the dataset paths and class names for the model:
yaml train: drone_yolo_dataset/train/images val: drone_yolo_dataset/val/images test: drone_yolo_dataset/test/images
nc: 1 # Number of classes names: ['drone_object'] # Class names Make sure this file is in the project root and correctly references the dataset folder paths.
π Training Script A minimal script to train the model using Ultralytics:
from ultralytics import YOLO import os
required_dirs = [ "drone_yolo_dataset/train/images", "drone_yolo_dataset/train/labels", "drone_yolo_dataset/val/images", "drone_yolo_dataset/val/labels", "drone_yolo_dataset/test/images", "drone_yolo_dataset/test/labels" ] for d in required_dirs: os.makedirs(d, exist_ok=True)
model.train( data="data.yaml", epochs=50, imgsz=640, batch=16, name="drone_yolo_model", project="runs/train", workers=4, val=True )
metrics = model.val(data="data.yaml", split="test") print("Test metrics:", metrics)
results = model.predict(source="drone_yolo_dataset/test/images", save=True) β Requirements
pip install ultralytics Ensure that torch and opencv-python are also installed for smooth training and prediction.
π Output Trained model weights: runs/train/drone_yolo_model/weights/best.pt
Prediction results saved in the current directory (with bounding boxes)
π Notes Label format follows YOLO: [class_id x_center y_center width height], all normalized.
Ensure correct image-label pairing (same filenames, different extensions).
You can visualize predictions using model.predict(...) or explore results using the YOLO UI.