YOLOv12 Object Detection Training Guide
This guide provides instructions for training an object detection model using YOLOv12. The example below demonstrates how to fine-tune the YOLOv12n model. Pre-trained checkpoints are available for download from the Ultralytics Releases page. You can see more at this URL: Ultralytics Releases
Prerequisites
Ensure you have the Ultralytics YOLO package installed.
Download the desired YOLOv12 model checkpoint (e.g., yolo12n.pt) using the provided script.
1 Downloading Pre-trained Models
To download YOLOv12 model checkpoints, run the following command:
python scripts/download_yolo_model.py \
--url <yolo_model_released_url> \
--output-dir <saved_yolo_model_path>
This will save the pre-trained weights to the ./ckpts/raw/ directory.
2 Process Dataset
Here is the CLI command to download and process datasets.
python scripts/download_and_process_datasets.py \
--output-dir <combined_dataset_path> \
--dataset-base-dir <directory_containing_all_datasets> \
--config <datasets_config_path> \
--platforms <list_of_platforms_to_download_from> \ # e.g., ["kaggle", "roboflow", "huggingface"]
--roboflow-api-key <roboflow_api_key> # Optional: required if "roboflow" is included in --platforms
For example:
python scripts/download_and_process_datasets.py \
--output-dir ./datasets/yolo_standard_dataset \
--dataset-base-dir ./datasets/all_datasets \
--config ./config/dataset_config.yaml \
--roboflow-api-key YOUR_ROBOFLOW_APIKEY \
--platforms "kaggle" "roboflow" "huggingface" # e.g., ["kaggle", "roboflow", "huggingface"]
For help:
python scripts/download_and_process_datasets.py -h
3 Fine-Tuning the Model
To fine-tune a YOLOv12 model for object detection, use the provided training script with customizable parameters. Run the following command and adjust the arguments based on your requirements:
yolo detect train \
model=<yolo_model_path or yolo_version_name> \
data=<dataset_config_path> \
epochs=<number_of_epochs> \
batch=<batch_size> \
patience=<early_stopping_patience> \
imgsz=<image_size> \
lr0=<initial_learning_rate> \
lrf=<final_learning_rate> \
device=<device_id or list_of_cuda or "cpu"> \
project=<output_directory> \
name=<experiment_name> \
save=<true or false> \
resume=<true or false>
Example Configuration
For reference, the equivalent configuration using the yolo CLI command is shown below:
yolo detect train \
model="./ckpts/raw/yolo12n.pt" \
data="./datasets/yolo_standard_dataset/data.yaml" \
epochs=100 \
batch=32 \
patience=20 \
imgsz=640 \
lr0=0.01 \
lrf=0.001 \
device=0 \
project="./ckpts/finetune/runs" \
name="license_plate_detector" \
save=true \
resume=false
More Configurations
Run this CLI command to show Help.
yolo --help