Skip to content

yakhyo/yolov8-crowdhuman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YOLOv8 Human Detection

GitHub Repository Downloads GitHub License

Human/person detection using YOLOv8 trained on CrowdHuman dataset with ONNX Runtime inference.

Features

  • 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

Installation

Clone the Repository

git clone https://github.com/yakhyo/yolov8-crowdhuman.git
cd yolov8-crowdhuman

Install Required Packages

pip install -r requirements.txt

Note: Requires CUDA for GPU acceleration. For CPU-only, replace onnxruntime-gpu with onnxruntime in requirements.txt.

Dataset Preparation

Convert CrowdHuman annotations to YOLO format:

python utils/crowdhuman2yolo.py

Edit 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

Training

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 Results

Training curves and metrics (100 epochs on CrowdHuman):

Precision-Recall Curve:

Confusion Matrix:

Sample Predictions:

Weights

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

Usage

# 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-img

Arguments

python 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)

Output

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

Reference

About

YOLOv8 trained on CrowdHuman dataset and supports ONNX Runtime Inference for Image, Video and Webcam

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages