This repository contains the code and resources for training and inferencing a YOLOv12 model for crack detection, specifically utilizing a dataset obtained from Roboflow.
- Project Description
- Dataset
- Prerequisites
- Installation
- Training the Model
- Inference (Making Predictions)
This project aims to develop a robust crack detection system using the YOLO (You Only Look Once) object detection framework. The model is trained on a specialized dataset of images containing various types of cracks, sourced and preprocessed using Roboflow. The goal is to accurately identify and localize cracks in images, which can be crucial for structural health monitoring, quality control, and maintenance.
Note on YOLOv12: This project assumes a "YOLOv12" implementation. The commands and structure provided here are generalized and should be adaptable. If "YOLOv12" refers to a custom fork or an experimental version, minor adjustments to commands (especially train.py and detect.py arguments) might be necessary based on your specific framework. For Ultralytics YOLO, the commands are typically very similar across versions.
The model is trained on a crack detection dataset.
Dataset Source: Roboflow Dataset Name: Concrete cracks Dataset Format: YOLOv12 (You can choose a different format if you wish)
To download your dataset from Roboflow:
-
Go to your Roboflow project page.
-
Select the desired version of your dataset.
-
Choose the export format (e.g., "YOLOv12 in our case).
-
Copy the provided download code snippet.
-
Place the downloaded dataset in the data/ directory (or wherever your data.yaml points).
Before you begin, ensure you have the following installed:
-
Python 3.9+
-
pip (Python package installer)
-
(Optional but Recommended) A virtual environment (e.g., venv or conda)
-
NVIDIA GPU with CUDA (for GPU acceleration, highly recommended for training)
-
git clone https://github.com/Sparshr04/Crackey.git
-
python -m venv venv \venv\Scripts\activate
python -m venv venv source venv/bin/activate -
pip install -r requirements.txt #(you might also directly use pip install ultralytics)
Training involves configuring your model, dataset, and training parameters.
-
Prepare your dataset: Ensure your Roboflow dataset is downloaded and placed in the correct directory, and your data.yaml file is configured to point to the train, val, and test image directories and defines your classes.
-
Choose a pre-trained model (optional but recommended): You can start training from a pre-trained YOLOv12 model checkpoint to leverage transfer learning. Common options include yolov12n.pt (nano), yolov12s.pt (small), etc. Place this .pt file in your project root or a designated weights/ directory.
-
yolo train model=yolov12n.pt data=data.yaml epochs=100 imgsz=640 batch=16 Explanation of arguments:Monitoring Training: Training progress, metrics (mAP, loss), and visualizations will be saved in the runs/train/your_run_name/ directory.
-
yolo train: The command to start training (for Ultralytics YOLO).
-
model=yolov12.pt: Path to your initial model weights (e.g., a pre-trained model or a blank model). If yolov12.pt is not a standard Ultralytics model, replace it with yolov8n.pt or similar.
-
data=data.yaml: Path to your dataset configuration file.
-
epochs=100: Number of training epochs. Adjust based on your dataset size and convergence.
-
imgsz=640: Input image size (e.g., 640x640 pixels).
-
batch=16: Batch size. Adjust based on your GPU memory.
-
Once your model is trained, you can use it to detect cracks in new images or videos.
-
Locate your trained weights: After training, your best model weights will be saved in runs/train/your_run_name/weights/best.pt.
-
CLI Interface is easy to use. Below are the usge examples for cli.
yolo detect predict model=runs/train/yolov12_crack_detection/weights/best.pt source=path/to/your/image.jpgyolo detect predict model=runs/train/yolov12_crack_detection/weights/best.pt source=path/to/your/image_folder/yolo detect predict model=runs/train/yolov12_crack_detection/weights/best.pt source=path/to/your/video.mp4yolo detect predict model=runs/train/yolov12_crack_detection/weights/best.pt source=0Note: '0' represents the default webcam
- model: Path to the trained YOLOv12 crack detection model weights
- source: Input source (image file, directory, video file, or webcam index)
The images/videos with detected cracks will be saved in a new directory, typically runs/detect/predict/.