YOLO Training Pipeline
YOLO Training Pipeline
This guide describes how to prepare a dataset and train a custom YOLO model using annotations created with Label Studio.
Prerequisites
Before starting, ensure that:
- Label Studio has been installed and configured
- A dataset has been annotated and exported
- Python 3.10 or later is available
- Ultralytics YOLO is installed
Export the Dataset
After annotating the documents in Label Studio, export the dataset using one of the supported formats.
The most commonly used formats are:
- COCO
- Pascal VOC XML
- YOLO
After the export operation, a ZIP archive containing the annotations will be downloaded.
Extract the Dataset
Extract the downloaded archive to a local directory.
For COCO exports, the archive typically contains:
- Images
- A JSON annotation file
- Category definitions
- Bounding box annotations
The JSON annotation file contains all information required to reconstruct the dataset and follows the COCO Dataset Format specification.
Convert the Dataset from COCO to YOLO
YOLO training requires annotations in YOLO format.
If the dataset was exported in COCO format, the annotations must be converted before training.
Create a Python conversion script and execute it against the exported COCO dataset.
The conversion process generates one annotation file (.txt) for each image.
Copy Images into the YOLO Dataset
The conversion process generates only the annotation files and does not move the images.
Copy the corresponding images into the YOLO dataset structure.
Dataset Structure
The training pipeline expects the following directory structure:
dataset/ ├── images/ │ ├── train/ │ └── val/ ├── labels/ │ ├── train/ │ └── val/ └── data.yaml
Where:
- images/train contains the training images
- images/val contains the validation images
- labels/train contains the training annotations
- labels/val contains the validation annotations
- data.yaml contains the dataset configuration
IMPORTANT
Each image must have a corresponding annotation file with the same filename.
Example:
images/train/invoice001.jpg labels/train/invoice001.txt
Create the data.yaml File
YOLO uses a configuration file named data.yaml to locate the dataset and identify the available classes.
The file specifies:
- Training image directory
- Validation image directory
- Number of classes
- Class names
Example:
path: dataset train: images/train val: images/val names: 0: invoice_number 1: date 2: seller_name 3: total
The class definitions must match those used during annotation.
Start the Training
Create a Python training script using the Ultralytics YOLO framework.
A pretrained YOLO model such as:
- yolo11n.pt
- yolo11s.pt
- yolo11m.pt
- yolo11l.pt
is required as the starting point for training.
The model does not need to be downloaded manually. Ultralytics automatically downloads it when the training script is executed.
Execute the training script.
During training, Ultralytics YOLO:
- Loads the dataset
- Trains the model
- Evaluates the model on the validation set
- Saves the best-performing weights
The number of iterations depends on:
- Dataset size
- Number of epochs
- Batch size
The batch size can be specified through the training parameters. Using -1 allows Ultralytics to select the default value automatically.
Training Output
At the end of the training process, Ultralytics creates a runs directory containing the training artifacts.
Typical outputs include:
- Training logs
- Validation metrics
- Loss curves
- Confusion matrix
- Model weights
The most important file is:
best.pt
This file contains the trained model and should be used for subsequent validation, conversion, or deployment.