Skip to content

XIQUQIX/roadblock_recognition_yolo8

Repository files navigation

Roadblock Detection Project

Overview

This project implements a roadblock detection system using the YOLOv8 model to identify roadblocks (e.g., cones, barriers) in images. The model is trained on a custom dataset and can be used for real-time detection in traffic scenarios.

Requirements

  • Hardware: CPU or NVIDIA GPU (e.g., RTX 3060 with CUDA 11.8)
  • OS: Windows/Linux
  • Software:
    • Python 3.8+
    • PyTorch 2.4.1+cu118
    • torchvision 0.19.1+cu118
    • ultralytics 8.3.x
    • opencv-python, numpy

Installation

  1. Set up Python environment:
    python -m venv yolo_env
    source yolo_env/bin/activate  # Linux/Mac
    yolo_env\Scripts\activate     # Windows
  2. Install dependencies:
    pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu118
    pip install ultralytics opencv-python numpy

Dataset

  • Location: block_data/
  • Structure:
    block_data/
    ├── images/
    │   ├── train/
    │   ├── val/
    │   ├── test/
    ├── labels/
    │   ├── train/
    │   ├── val/
    │   ├── test/
    ├── data.yaml
    
  • Format:
    • Images: .jpg
    • Labels: .txt (YOLO format: class_id x_center y_center width height, normalized to 0-1)
    • data.yaml:
      train: ./images/train
      val: ./images/val
      test: ./images/test
      nc: 1
      names: ['block']

Training

  1. Train the model (in Jupyter Notebook or Python script):
    from ultralytics import YOLO
    
    model = YOLO("yolov8n.pt")
    model.train(
        data="block_data/data.yaml",
        epochs=50,
        imgsz=416,
        batch=8,
        device=0,  # Use GPU (or 'cpu' if no GPU)
        amp=False,
        name='block_train',
        project='runs/train',
        exist_ok=True
    )
  2. Output:
    • Trained weights: runs/train/block_train/weights/best.pt
    • Training logs: runs/train/block_train/results.png

Testing

  1. Test on a single image:
    from ultralytics import YOLO
    
    model = YOLO("runs/train/block_train/weights/best.pt")
    results = model("block_data/images/test/test_image.jpg", device=0)
    results.show()
    results.save(save_dir='runs/detect/test')
  2. Evaluate on validation set:
    model.val(data="block_data/data.yaml", device=0)

Deployment

  • Local:
    • Run training/testing in Jupyter Notebook or Python scripts.
  • Remote (Company Server):
    • Upload block_data and scripts to ~/yolo_project via FileZilla (IP: 10.31.15.53, user: zhusongyu, password: zhusongyu123, port: 22).
    • Run on server:
      ssh zhusongyu@10.31.15.53 -p 22
      cd ~/yolo_project
      source yolo_env/bin/activate
      python train_yolov8.py

Notes

  • GPU Issues: If NotImplementedError occurs, ensure torchvision is CUDA-enabled (0.19.1+cu118). Use device='cpu' as fallback.
  • Dataset: Ensure each image has a corresponding label file. Split dataset into train/val/test (80:10:10) using split_dataset.py.
  • Performance: Adjust epochs, imgsz, or batch based on dataset size and hardware.

About

Applied yolo8 to recognize roadblocks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published