File size: 4,065 Bytes
ce500ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# 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](https://github.com/ultralytics/assets/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:
```bash
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.
```bash
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:
```bash
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:
```bash
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:
```bash
python scripts/train_yolo.py \
--epochs <number_of_epochs> \
--batch <batch_size> \
--device <cuda_device_id_or_list|cpu> \
--project <path_to_save_results> \
--name <project_name> \
--resume # Optional: resume training from the last checkpoint
```
### Example Configuration
For reference, the equivalent configuration using the yolo CLI command is shown below:
```bash
python scripts/train_yolo.py\
--epochs 100 \
--batch 32 \
--device 0 \
--project "./ckpts/finetune/runs" \
--name "license_plate_detector"
```
### More Configurations
Run this CLI command to show `Help`.
```bash
python scripts/train_yolo.py -h
```
-->
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:
```bash
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:
```bash
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`.
```bash
yolo --help
```
## Using PaddleOCR
|