# π¦ 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.