This project utilizes YOLOv8 to detect potholes in images and videos. It involves dataset preparation, model training, evaluation, and inference on test data.
Ensure you have the following installed:
- Python 3.10+
- PyTorch 2.3.1+cu121
- NVIDIA GPU with CUDA 12.2 (recommended)
- Clone the repository (if applicable).
- Install required dependencies:
pip install ultralytics==8.0.0 roboflow
- Check if Ultralytics YOLOv8 is correctly installed:
import ultralytics ultralytics.checks()
- Create a dataset directory:
mkdir -p /content/datasets
- Download the dataset from Roboflow:
from roboflow import Roboflow rf = Roboflow(api_key="YOUR_API_KEY") project = rf.workspace("YOUR_NAME").project("yolov8pothole") version = project.version(1) dataset = version.download("yolov5")
Train the model using the following command:
cd /content
yolo task=detect mode=train model=yolov8m.pt data=/content/Yolov8Pothole-1/data.yaml epochs=70 imgsz=640
- Confusion Matrix:
from IPython.display import Image Image(filename='/content/runs/detect/train2/confusion_matrix.png', width=900)
- Training and Validation Loss:
Image(filename='/content/runs/detect/train2/results.png', width=600)
- Validation Batch Predictions:
Image(filename='/content/runs/detect/train2/val_batch0_pred.jpg', width=600)
- Validate with best weights:
yolo task=detect mode=val model=/content/runs/detect/train2/weights/best.pt data=/content/datasets/Yolov8Pothole-1/data.yaml
yolo task=detect mode=predict model=/content/runs/detect/train2/weights/best.pt conf=0.25 source=/content/datasets/Yolov8Pothole-1/test/images
cp "/content/drive/MyDrive/Pothole Detect/demo2.mp4" .
yolo task=detect mode=predict model=/content/runs/detect/train2/weights/best.pt conf=0.25 source='/content/demo2.mp4'
from IPython.display import HTML
from base64 import b64encode
import os
# Input video path
save_path = '/content/runs/detect/predict3/demo2.mp4'
compressed_path = "/content/result_compressed2.mp4"
os.system(f"ffmpeg -i {save_path} -vcodec libx264 {compressed_path}")
# Show video
mp4 = open(compressed_path,'rb').read()
data_url = "data:video/mp4;base64," + b64encode(mp4).decode()
HTML(f"""
<video width=600 controls>
<source src='{data_url}' type='video/mp4'>
</video>
""")
- Ensure all paths exist before executing commands.
- Check that your dataset is downloaded correctly.
- Ensure your GPU is available and properly set up with CUDA.
This README provides step-by-step instructions for setting up, training, and evaluating a pothole detection model using YOLOv8. Let me know if you need further refinements!