Fine-tune a vision model on your images
Train a detector for your own objects with Ultralytics YOLO. Put your images and labels in YOLO format into a folder, one text file per image with one line per object: class, then the box center, width and height as fractions of the image size.
vision/
data.yaml
train.py
shapes/
images/train/0001.jpg … labels/train/0001.txt …
images/val/0001.jpg … labels/val/0001.txt …
data.yaml names the folders and the classes:
# Paths are relative to this file.
train: shapes/images/train
val: shapes/images/val
names:
0: circle
1: square
train.py starts from pretrained weights, trains, evaluates and exports the model to ONNX:
from pathlib import Path
from ultralytics import YOLO
out = Path("output").resolve()
model = YOLO("yolo11n.pt") # pretrained weights, downloaded on first use
model.train(data="data.yaml", epochs=30, imgsz=320, batch=32, project=out, name="shapes", exist_ok=True)
metrics = model.val()
print(f"mAP50-95: {metrics.box.map:.3f}")
model.export(format="onnx") # next to best.pt: output/shapes/weights/best.onnx
Run it:
nido create train --gpu l4 --network github.com --network release-assets.githubusercontent.com \
--network pypi.org --network files.pythonhosted.org
nido cp ./vision train:/sandbox/vision
nido exec train -- uv pip install onnx onnxslim onnxruntime
nido exec train -- bash -c "cd /sandbox/vision && python train.py"
nido cp train:/sandbox/vision/output ./output
On 160 small images this takes about a minute. output/shapes/weights then holds best.pt and
best.onnx, next to the training curves and a confusion matrix. The weights are yours.
To keep the run going in the background, or to run it as one task, see Long runs.