Trrafic-Sign-and-Pothole_De.../GUIDE_TRAIN_TEST_YOLO.md
2026-02-09 12:50:10 +05:30

2.5 KiB

YOLOv8 Training & Testing Guide

This guide details how to prepare your dataset, train the YOLOv8 model for Potholes and Road Signs, and test the trained model.

1. Dataset Preparation

YOLOv8 requires data in a specific format.

A. Data Structure

Organize your dataset folder like this:

datasets/
  road_signs_potholes/
    train/
      images/
        img1.jpg
        ...
      labels/
        img1.txt
        ...
    val/
      images/
        ...
      labels/
        ...
    data.yaml

B. Label Format

Each .txt file in labels/ corresponds to an image. Format: class_id center_x center_y width height (normalized 0-1).

Example img1.txt:

0 0.5 0.5 0.2 0.3
1 0.1 0.1 0.05 0.1

Class IDs Mapping (Example):

  • 0: Traffic Sign
  • 1: Pothole
  • 2: Manhole

C. Creating data.yaml

Create a data.yaml file inside your dataset folder (or anywhere accessible).

path: ../datasets/road_signs_potholes # dataset root dir
train: train/images # train images (relative to 'path')
val: val/images # val images (relative to 'path')

# Classes
names:
  0: Traffic Sign
  1: Pothole
  2: Manhole

2. Training the Model

We have provided a script backend/models/train_yolo.py.

Command: Open your terminal in d:\Time-Pass-Projects\pothole-roadsign detection.

# Activate your environment if needed
python backend/models/train_yolo.py

Note: You will need to edit backend/models/train_yolo.py slightly to point to your actual data.yaml path if you haven't already, or pass it as an argument if you modify the script to accept args.

Training Process:

  1. The script downloads yolov8n.pt (nano) as a starting point.
  2. It runs for 50 epochs (adjustable).
  3. Result: Weights are saved in runs/detect/train/weights/best.pt.

3. Testing the Model

Once trained, you should test it visually.

A. Locate your specific model

Find runs/detect/trainX/weights/best.pt. Copy this file to backend/models/best.pt (or update paths in scripts).

B. Run the Test Script

We have created backend/test_model.py for quick verification.

python backend/test_model.py

Make sure to update the video_path or image_path in test_model.py to point to a real file.

4. Integration

After you are satisfied with best.pt:

  1. Move best.pt to backend/models/.
  2. Updates backend/pipelines/video_processor.py line 10:
    self.yolo = YOLOManager("backend/models/best.pt")