Skip to content

About

YOLOv8 object detection pipeline: dataset prep, training, evaluation and an inference API.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YOLOv8 Object Detection Pipeline

A comprehensive object detection pipeline built on Ultralytics YOLOv8, providing end-to-end support for custom dataset preparation, model training with advanced augmentation strategies, evaluation, and real-time inference via a FastAPI service.

Features

  • Dataset Preparation -- Convert COCO and Pascal VOC annotations to YOLO format, split datasets with stratification, validate annotations, and analyze class distributions.
  • Training -- Full training loop with configurable hyperparameters, augmentation pipelines (mosaic, mixup, HSV jitter, geometric transforms), checkpoint resumption, and multi-format model export.
  • Evaluation -- Compute mAP@50 and mAP@50-95, per-class precision/recall/F1, confusion matrices, precision-recall curves, error analysis, and inference speed benchmarks.
  • Inference -- Single image, batch directory, video file, and live webcam/RTSP stream detection with configurable NMS, confidence filtering, and region-of-interest masking.
  • REST API -- FastAPI service with endpoints for image detection, annotated image responses, real-time WebSocket streaming, and model introspection.

Project Structure

yolov8-object-detection/
├── configs/
│   └── training_config.yaml
├── src/
│   ├── dataset_preparation.py
│   ├── trainer.py
│   ├── inference.py
│   ├── evaluation.py
│   └── api.py
├── requirements.txt
├── .gitignore
└── README.md

Quick Start

Installation

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Prepare a Dataset

from src.dataset_preparation import DatasetPreparator

preparator = DatasetPreparator(data_dir="./data/raw", output_dir="./data/prepared")
preparator.convert_coco_to_yolo("annotations.json", "images/")
preparator.split_dataset(train_ratio=0.8, val_ratio=0.15, test_ratio=0.05)
preparator.create_dataset_yaml(class_names=["car", "truck", "pedestrian", "cyclist"])
preparator.compute_class_distribution()

Train a Model

from src.trainer import YOLOTrainer

trainer = YOLOTrainer(config_path="configs/training_config.yaml")
trainer.setup_model()
trainer.configure_augmentations()
results = trainer.train()
trainer.export_model(format="onnx")

Run Inference

from src.inference import YOLOInference

detector = YOLOInference(model_path="runs/detect/train/weights/best.pt")
detections = detector.detect_image("test.jpg", confidence=0.4)
detector.draw_detections("test.jpg", detections, output_path="result.jpg")

Evaluate Performance

from src.evaluation import YOLOEvaluator

evaluator = YOLOEvaluator(model_path="runs/detect/train/weights/best.pt")
metrics = evaluator.evaluate(data_yaml="data/prepared/dataset.yaml")
evaluator.plot_confusion_matrix(save_path="confusion_matrix.png")
evaluator.speed_benchmark(image_size=640, batch_sizes=[1, 8, 16, 32])

Start the API Server

uvicorn src.api:app --host 0.0.0.0 --port 8000

API Endpoints

Method Endpoint Description
POST /detect Upload an image and receive detection results as JSON
POST /detect/annotated Upload an image and receive an annotated image
WS /ws/stream WebSocket endpoint for real-time detection streaming
GET /model/info Retrieve model metadata and configuration
GET /health Health check

Training Configuration

All training parameters are managed through configs/training_config.yaml. Key settings include model architecture selection (yolov8n through yolov8x), augmentation strengths, optimizer configuration, and early stopping patience.

Model Export

Trained models can be exported to multiple formats for deployment:

  • ONNX -- Cross-platform inference
  • TensorRT -- Optimized NVIDIA GPU inference
  • CoreML -- Apple device deployment
  • OpenVINO -- Intel hardware acceleration

Requirements

  • Python 3.9+
  • CUDA-capable GPU recommended for training
  • See requirements.txt for full dependency list

License

MIT License

About

YOLOv8 object detection pipeline: dataset prep, training, evaluation and an inference API.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages