تفاصيل العمل

# README.md

# Pothole Detection and Training using YOLOv8

This project focuses on detecting potholes in road images and videos using computer vision techniques powered by the YOLOv8 model.

It includes both the model training process and the real-time detection script.

---

## Project Overview

- Detects potholes from video or webcam using a YOLOv8 model.

- Saves cropped pothole images locally.

- Generates random (dummy) GPS coordinates for each detected pothole.

- Trained and evaluated using a dataset from Roboflow on Google Colab.

- Can export trained model to ONNX for deployment.

## Model

- **Architecture**: YOLOv8 (Nano segmentation model: `yolov8n-seg.pt`)

- **Framework**: Ultralytics YOLO (v8)

- **Training Platform**: Google Colab

- **Dataset Source**: Custom pothole detection dataset downloaded from [Roboflow](https://roboflow.com/).

<!-- I used 3997 images, %70 2796(train), %20 800(valid) and %10 401(test)

nc: 1

names: ['pothole'] -->

- **Customizations**:

- Training from scratch or from checkpoints.

- Exports to ONNX format for compatibility.

## Dataset

The dataset was downloaded from Roboflow using the API, and contains labeled images for pothole detection.

```python

from roboflow import Roboflow

rf = Roboflow(api_key="YOUR_API_KEY")

project = rf.workspace("YOUR_WORKSPACE").project("YOUR_PROJECT")

dataset = project.version(VERSION).download("yolov8")

---

## Project Structure

```

pothole_detection_yolov8_project/

├── inference/ # Folder for inference (running the model)

│ ├── model/ # Contains the trained model file

│ │ └── best.pt # Best trained YOLOv8 model

│ └── infer-pothole-detection.py # Script to detect potholes using the model

├── sample results/

├── v

└── v1

├── train/ # Training scripts and notebooks

│ └── train_pothole_detection.ipynb # Notebook to train the model

│ └── train_pothole_detection.py

│ └── results/

├── video/

│ └── p

├── README.md # Project description and instructions

├── requirements.txt # List of required Python libraries

```

---

## Installation

Install the required dependencies:

```bash

pip install -r requirements.txt

```

---

## Requirements

The project uses the following Python libraries:

- `ultralytics==8.3.119`

- `opencv-python==4.11.0.86`

- `cvzone==1.5.6`

- `roboflow==1.1.61`

- `matplotlib==3.10.0`

(Ensure Python 3.8 or newer is installed.)

---

## Model Training (Google Colab)

**Steps:**

1. Install necessary libraries: `ultralytics`, `roboflow`.

2. Download dataset from Roboflow.

3. Initialize YOLOv8 model.

4. Train model for 200 epochs on 640x640 images.

5. Save best and last weights to Google Drive.

6. Validate the model performance on validation and test sets.

7. Export the trained model to ONNX format.

**Important Colab Commands:**

- Mount Google Drive to save training results.

- Set `save_period=5` to save weights every 5 epochs.

- Enable early stopping if no improvement for 10 epochs.

- Use GPU device for faster training.

> Training code is organized into 7 main cells: installing libraries, downloading dataset, loading model, training, validation, testing, and exporting model.

---

## Real-time Detection Script

**Steps to run detection:**

1. Place your video file in the working directory.

2. Edit the `inference/infer_pothole_detection.py` file:

- Set the correct path to the trained model.

- Set the correct video path.

3. Run the detection script:

```bash

python inference/infer_pothole_detection.py

```

- Press **'q'** to exit the detection window.

- Detected potholes will be saved as cropped images.

- Dummy GPS coordinates will be generated and saved in text files.

---

## Sample Outputs

- Real-time pothole bounding boxes drawn on video frames.

- Cropped pothole images saved in the `pothole_images/` folder.

- Generated (dummy) latitude and longitude coordinates saved in `pothole_coordinationes/`.

---

## Performance

### Quantitative Metrics

The model's performance was evaluated using the validation set after training for 195 epochs. Below are the key metrics:

| Metric | Value |

|---------------------|--------|

| mAP@0.5 (Box) | 0.781 |

| mAP@0.5:0.95 (Box) | 0.545 |

| mAP@0.5 (Mask) | 0.744 |

| mAP@0.5:0.95 (Mask) | 0.456 |

| Precision (Box) | 0.87 |

| Recall (Box) | 0.70 |

- **Confusion Matrix** (Validation Set):

- **True Positives (Potholes correctly identified)**: 1628

- **False Negatives (Potholes missed)**: 407

- **False Positives (Background identified as potholes)**: 538

- **Normalized Metrics**:

- 75% of actual potholes were correctly identified.

- 25% of actual potholes were missed (classified as background).

- 12% of background was incorrectly classified as potholes.

## Future Improvements

- Replace dummy coordinates with real GPS data.

- Improve model accuracy by training on a larger and more diverse dataset.

- Deploy the model as a web application or mobile app.

---

## Author

- **EngFAI** — [EngFAI](https://github.com/EngFAI)

---

ملفات مرفقة

بطاقة العمل

اسم المستقل
عدد الإعجابات
0
عدد المشاهدات
38
تاريخ الإضافة
تاريخ الإنجاز