Human/person detection using YOLOv8 trained on CrowdHuman dataset with ONNX Runtime inference.
- CrowdHuman to YOLO format conversion
- YOLOv8n training pipeline
- ONNX Runtime GPU (CUDA) inference
- TorchVision NMS for real-time performance
- Support for image, video, and webcam
git clone https://github.com/yakhyo/yolov8-crowdhuman.git
cd yolov8-crowdhumanpip install -r requirements.txtNote: Requires CUDA for GPU acceleration. For CPU-only, replace onnxruntime-gpu with onnxruntime in requirements.txt.
Convert CrowdHuman annotations to YOLO format:
python utils/crowdhuman2yolo.pyEdit the script to specify your paths:
convert_odgt_to_yolo("annotation_val.odgt", "data/val/images", "data/val/labels")Expected dataset structure:
CrowdHuman/
├── data/
│ ├── train/
│ │ ├── images/
│ │ └── labels/
│ └── val/
│ ├── images/
│ └── labels/
└── dataset.yaml
Train YOLOv8n on CrowdHuman:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(
data='dataset.yaml',
epochs=100,
imgsz=640,
batch=16,
name='yolov8n-person',
project='runs/train'
)Export to ONNX:
from ultralytics import YOLO
model = YOLO("runs/train/yolov8n-person/weights/best.pt")
model.export(format="onnx", simplify=True, dynamic=True)Training curves and metrics (100 epochs on CrowdHuman):
Precision-Recall Curve:
Confusion Matrix:
Sample Predictions:
Pre-trained weights are available in the weights/ directory:
| Model | PyTorch | ONNX |
|---|---|---|
| YOLOv8n-person (best) | yolov8n_best.pt | yolov8n_best.onnx |
| YOLOv8n-person (last) | yolov8n_last.pt | yolov8n_last.onnx |
# Webcam (display auto-enabled)
python inference.py --weights weights/yolov8n_best.onnx --source 0
# Image
python inference.py --weights weights/yolov8n_best.onnx --source assets/test.jpg --save-img --view-img
# Video
python inference.py --weights weights/yolov8n_best.onnx --source video.mp4 --save-img --view-imgpython inference.py -h
usage: inference.py [-h] [--weights WEIGHTS] [--source SOURCE] [--conf-thres CONF_THRES] [--iou-thres IOU_THRES] [--max-det MAX_DET] [--save-img] [--view-img]
YOLOv8 Human Detection ONNX Inference
options:
-h, --help show this help message and exit
--weights WEIGHTS Path to ONNX model file
--source SOURCE Path to image/video file or webcam index
--conf-thres CONF_THRES
Confidence threshold
--iou-thres IOU_THRES
NMS IoU threshold
--max-det MAX_DET Maximum detections per image
--save-img Save detected images
--view-img Display results (auto-enabled for webcam)
The model returns detections as numpy arrays:
- boxes:
[N, 4]bounding boxes in (x1, y1, x2, y2) format -numpy.float32 - scores:
[N]confidence scores -numpy.float32 - class_ids:
[N]class indices -numpy.int32
- Ultralytics: ultralytics/ultralytics
- CrowdHuman: CrowdHuman Dataset




