Enos-123's picture
Update Readme.md
b8bb3af verified
# 🚦 Accident Detection using YOLOv8

A real-time traffic accident evaluator and severity classifier built using the **YOLOv8x** object detection model, trained on the [Roboflow Accident Evaluator Dataset](https://universe.roboflow.com/accident-evaluator).

---

## πŸ“Œ Project Overview

This project aims to detect and classify traffic accident-related scenarios in surveillance footage or images. The model can identify:

- πŸš‘ Detected Injury  
- πŸ”₯ Fire  
- πŸ“ˆ High Severity  
- ⚠️ Low Severity  
- βš™οΈ Medium Severity  
- πŸ’¨ Smoke  

The model is fine-tuned using **YOLOv8x** and trained in stages up to **120 epochs** for optimal accuracy.

---

## πŸ” Dataset Details

- πŸ“¦ **Source**: Roboflow Universe  
- πŸ–ΌοΈ **Images**: 3,000+  
- 🏷️ **Classes**: 6  
- πŸ“ Format: YOLO with `.txt` annotations

We used the dataset in the following folder structure:

accident-evaluator-3/ β”œβ”€β”€ train/ β”œβ”€β”€ valid/ β”œβ”€β”€ test/ └── data.yaml


---

## πŸš€ Model Training

We trained the model in **incremental steps of 20–30 epochs** with manual control to resume/stop as needed. Key configurations:

```python
from ultralytics import YOLO

model = YOLO("yolov8x.pt")
model.train(
    data="data.yaml",
    epochs=50,
    imgsz=640,
    batch=16,
    optimizer="SGD",
    lr0=0.001,
    device=0,
    warmup_epochs=3,
    patience=15,
    cache=True,
    mosaic=1.0,
    mixup=0.1,
    fliplr=0.5,
)

πŸ“Œ Early stopping was enabled to avoid overfitting.


πŸ“ˆ Validation Results (Epoch 120)

Metric Score
[email protected] 0.697
[email protected]:0.95 0.438
Precision 0.764
Recall 0.646

Per-Class Accuracy:

Class [email protected]
Detected-Injury 0.741
Fire 0.611
High 0.869
Low 0.834
Medium 0.795
Smoke 0.331

πŸ§ͺ Inference on Custom Image

from ultralytics import YOLO

model = YOLO("best.pt")  # path to the final trained model
results = model("your-image.jpg", save=True, imgsz=640)
results.show()

πŸ“ Folder Structure

project/
β”œβ”€β”€ accident-evaluator-3/     # Dataset
β”œβ”€β”€ training_stages/          # Saved model weights per stage
β”œβ”€β”€ runs/detect/train/        # YOLO output folders
β”œβ”€β”€ best.pt                   # Final trained model
└── README.md

πŸ› οΈ Future Work

  • βœ… Improve underperforming classes (like smoke)
  • βœ… Deploy as a Flask web app or streamlit dashboard
  • βœ… Integrate into live CCTV/RTSP camera feeds
  • βœ… Export to ONNX or TensorRT for real-time deployment

πŸ‘¨β€πŸ’» Author

Developed by [Your Name] – passionate about AI for social impact. Reach out on LinkedIn or email at [email protected].


πŸ“„ License

This project is licensed under the MIT License.