A complete, modular pipeline for training a YOLOv8 model to detect humans in disaster scenarios using UAV / drone footage.
Dataset: SARD by Roboflow — 1,980 images, 6 classes
Model: YOLOv8s (pretrained COCO → fine-tuned)
D:/MLModel/
├── setup.py # Install dependencies
├── verify_dataset.py # Dataset integrity check + class distribution
├── data_uav.yaml # Dataset config (absolute paths)
├── train.py # Full training pipeline (UAV-tuned)
├── validate.py # Post-training evaluation (mAP, confusion matrix)
├── inference.py # Image / video / folder inference
├── export_model.py # Export to ONNX / TensorRT / OpenVINO
├── uav_realtime.py # Real-time OpenCV stream inference
└── README.md # This file
search-and-rescue-2/
├── data.yaml # Original Roboflow config (relative paths)
├── train/images + labels/
├── valid/images + labels/
└── test/images + labels/
python setup.pypython verify_dataset.pyChecks image/label counts, validates YOLO format, prints class distribution.
# Full training (100 epochs, GPU)
python train.py
# Smoke test (validate pipeline in 1 epoch)
python train.py --epochs 1 --batch 4 --imgsz 320 --name sar_smoke_testBest weights → runs/detect/sar_uav/weights/best.pt
python validate.py --weights runs/detect/sar_uav/weights/best.ptOutputs mAP50, mAP50-95, precision, recall per class + confusion matrix PNG.
# Image folder
python inference.py --source D:/MLModel/search-and-rescue-2/test/images
# Drone video
python inference.py --source D:/footage/drone_clip.mp4 --conf 0.15# Webcam
python uav_realtime.py
# RTSP drone stream
python uav_realtime.py --source rtsp://192.168.1.1/stream --conf 0.20# ONNX (portable)
python export_model.py --format onnx
# TensorRT (Nvidia Jetson / server GPU)
python export_model.py --format engine --half| ID | Class | Priority |
|---|---|---|
| 0 | Running | Low |
| 1 | Walking | Low |
| 2 | laying_down | 🔴 HIGH — incapacitated victim |
| 3 | not_defined | Medium |
| 4 | seated | Medium |
| 5 | stands | Low |
| Parameter | Value | Reason |
|---|---|---|
imgsz |
640 | Standard; raise to 1280 for very high-alt footage |
mosaic |
1.0 | Tile 4 images → small object diversity |
scale |
0.6 | Simulates altitude change |
degrees |
15.0 | UAV yaw variation |
hsv_s |
0.7 | Haze / smoke robustness |
hsv_v |
0.4 | Day / night variation |
flipud |
0.3 | Nadir vs oblique shots |
copy_paste |
0.1 | Boosts small object recall |
patience |
20 | Early stopping |
In SAR, missing a victim is worse than a false alarm. Prioritise recall.
- Lower confidence threshold:
--conf 0.15at inference time - Class imbalance: Check
laying_downcount — augment or collect more data - Focal loss: Set
fl_gamma=1.5intrain.pyDEFAULTS to focus on hard negatives - Larger model:
--model yolov8m.ptoryolov8l.ptfor more accuracy - Multi-scale training: Try
imgsz=1280if GPU allows (catches smaller subjects)
python export_model.py --format engine --half --device 0
python uav_realtime.py --source rtsp://<drone-ip>/stream --headless --save output.mp4import onnxruntime as ort, cv2, numpy as np
sess = ort.InferenceSession("best.onnx", providers=["CUDAExecutionProvider"])
frame = cv2.resize(cv2.imread("frame.jpg"), (640, 640))
inp = (frame[...,::-1].transpose(2,0,1)[None] / 255.).astype("float32")
preds = sess.run(None, {sess.get_inputs()[0].name: inp})| Strategy | Command | Notes |
|---|---|---|
| COCO pretrained (default) | --model yolov8s.pt |
Best starting point |
| Full fine-tune | (default) | Recommended |
| Freeze backbone | Set freeze=10 in train.py |
Faster, less GPU memory |
| Resume training | --resume |
Continue from last checkpoint |