YOLOv11n Fine‑Tuning Workflow
Prepare the Fine‑Tuning Environment
Set up a Python virtual environment, copy necessary scripts and data, and install Ultralytics to fine‑tune the YOLOv11n model.
Fine‑tuning a YOLOv11n model requires a clean Python environment with the Ultralytics framework and your dataset. Follow these steps on a machine with a powerful GPU (not the Raspberry Pi):
# Create and activate a virtual environment in your home directory
cd
python3 -m venv finetune
cd finetune
source bin/activate
# Set up a directory structure for scripts, data and models
mkdir scripts
cp ~/repos/common_platform/scripts/ls_to_yolo.py scripts/
cp ~/repos/common_platform/scripts/make_split_and_yaml.py scripts/
cp ~/repos/common_platform/scripts/prune_images_without_boxes.py scripts/
mkdir -p data/images_raw
cp ~/teleop_data/images/* data/images_raw/
cp -r ~/teleop_data/annotations data/
mkdir models
cp ~/code/common_platform/models/yolo11n.pt models/
mkdir runs
# Install Ultralytics
pip install ultralytics
Convert Label Studio Annotations to YOLO Format
Convert exported Label Studio JSON annotations into YOLO‑style text files and create train/validation splits.
Ultralytics expects your dataset to be in the YOLO text format with separate directories for training and validation images and labels. Use the provided conversion scripts to transform the Label Studio JSON files into this structure and generate a data.yaml file describing the dataset.
# Convert Label Studio JSON to YOLO text files
python3 scripts/ls_to_yolo.py
# Split data into training and validation sets and create data.yaml
python3 scripts/make_split_and_yaml.py
Prune the Dataset
Remove images without bounding boxes from the dataset to ensure training only uses labeled data.
After splitting your dataset, there may still be images that contain no annotations. These unlabeled images can negatively affect calibration and training. Use the pruning script to remove them.
# Remove images without boxes from your raw image set
python3 scripts/prune_images_without_boxes.py --images-dir data/images_raw --annotations-dir data/annotations --delete
Edit the `data.yaml` File
Update the generated data.yaml to reflect the correct class names for your dataset.
The make_split_and_yaml.py script creates a data.yaml file with placeholder class names (class_0, class_1, etc.). You must replace these names with the actual class labels used in your dataset. Open data.yaml and edit the names list:
nano data.yaml
Verify Ultralytics Installation
Run a quick training on a toy dataset to confirm that the Ultralytics YOLO toolkit is installed correctly.
Before starting a long training job, it’s a good idea to test your Ultralytics installation by training on a small dataset. This confirms that the CLI works and that all dependencies are installed.
# Train on the tiny COCO8 dataset for one epoch
yolo detect train model=yolo11n.pt data=coco8.yaml epochs=1 imgsz=640
Fine‑Tune the YOLOv11n Model
Train a YOLOv11n model on your custom dataset using Ultralytics. This step performs the actual fine‑tuning and requires significant compute resources.
Fine‑tuning will adjust the weights of a pre‑trained YOLOv11n model to detect your specific classes. Use a machine with a powerful GPU and plenty of memory. Adjust the batch size to fit your hardware; recommended values are provided in the table below.
# Train YOLOv11n on your dataset
yolo train model=models/yolo11n.pt data=data.yaml epochs=100 imgsz=640 batch=16 project=runs name=y11n_finetune
Recommended batch sizes
Hardware Recommendedbatch
M1 / M2 / M3 MacBook Air
8
M1 / M2 / M3 Pro (16 GB)
16
M1 / M2 / M3 Max (32–64 GB)
32
Intel Mac (CPU only)
4 (or 2)
Adjust batch on the command line to match your hardware. Use the device=mps argument on Apple Silicon to leverage the Metal GPU.
Export the Fine‑Tuned Model to ONNX
Convert the best YOLOv11n weights into an ONNX file for Hailo compilation and copy it to another machine if needed.
After training, convert your best model weights into the ONNX format. Ultralytics provides an export command to perform this conversion. After exporting, you may want to rename the file and copy it to your calibration machine for compilation.
cd runs/train/y11n_finetune/weights
yolo export model=best.pt format=onnx imgsz=640 simplify=True nms=False
mv best.onnx yolov11n_finetune.onnx
# Copy the ONNX model to your Hailo compilation machine
scp yolov11n_finetune.onnx <USER>@<HOSTNAME>:~