Ultralytics YOLO is a free, open-source toolkit for training your own object-detection AI: teach it to spot your products on a shelf, birds at a feeder or faults on a circuit board, then run the model on your PC. Training on your own graphics card means your images never leave your machine and there's no cloud bill. Contains no training times or accuracy results of our own.
If you only want to use a ready-made detector for home security cameras rather than train one, our guide to setting up Frigate for local AI object detection is the better starting point.
What you need
Item | What Ultralytics documents |
|---|
Python | 3.8 or newer |
PyTorch | 1.8 or newer; install a CUDA build first if you have an NVIDIA card |
GPU | Optional. Training uses GPU 0 when one is available and falls back to the CPU otherwise |
Other GPUs | AMD via a PyTorch ROCm build on Linux, Intel via device=xpu:0, Apple silicon via device=mps |
Model | A pretrained checkpoint such as yolo26n.pt, which downloads automatically |
Data | Your own labelled images in YOLO format (covered below) |
Ultralytics doesn't publish a minimum VRAM figure for training. Memory use depends on the model size, image size and batch size, and the training page offers an automatic batch mode (covered in step 5) that sizes the batch to your card. A 16GB card such as the ASUS RTX 5060 Ti 16GB Dual OC (the 16GB model, not the 8GB version) gives more room for larger models and bigger batches than an 8GB card. NVIDIA lists the RTX 5060 Ti with 16GB or 8GB of GDDR7, so check which version you're buying.
Step 1: Install PyTorch, then Ultralytics
Ultralytics' quickstart notes that PyTorch requirements vary by operating system and CUDA version, and recommends installing PyTorch first if you need a specific build. On Windows with an NVIDIA card, follow our guide to installing PyTorch with CUDA on Windows. AMD owners should see installing PyTorch with ROCm on Windows, though Ultralytics' own docs describe AMD training on Linux, and Intel Arc owners can use installing PyTorch for Intel Arc on Windows.
Then, inside a Python virtual environment, install the package:
pip install -U ultralytics
Ultralytics also documents a conda-forge install and an official Docker image. If you'd rather keep AI tools in Linux, see how to set up WSL2 for GPU local AI.
Step 2: Check it works
Run a first prediction from the terminal:
yolo predict model=yolo26n.pt
The pretrained weights download automatically, the model runs on two bundled sample images, and the command prints where it saved the annotated results (runs/detect/predict on a first run). If this falls back to the CPU on a PC with an NVIDIA card, PyTorch can't see your GPU; our guide to fixing "PyTorch CUDA not available" covers the usual causes.
Step 3: Label your images
Each training image needs a matching text file describing the objects in it. Ultralytics' YOLO format rules are:
One .txt file per image, with the same name. Images with no objects don't need a file.
One row per object: class x_center y_center width height.
Box coordinates are normalised from 0 to 1, so divide pixel values by the image width and height.
Class numbers start at 0.
You won't type these by hand. A free labelling tool draws the boxes and writes the files for you: X-AnyLabeling (a desktop app), CVAT Community and Label Studio (both run as local web apps) all list YOLO export. If you have a COCO-format dataset instead, Ultralytics' datasets page documents a convert_coco tool for converting it to YOLO labels.
Step 4: Write a dataset YAML file
Split your labelled images into a training set and a validation set, organised as in Ultralytics' small COCO8 example dataset (its YAML points at images/train and images/val), then create a YAML file such as mydata.yaml:
path: datasets/mydata
train: images/train
val: images/val
names:
0: robin
1: blue tit
path is the dataset root, train and val are relative to it, and names maps each class number to a name. The validation set is what Ultralytics uses to pick the best checkpoint, so keep some images out of training.
Step 5: Start training
Start from a pretrained model, which Ultralytics recommends for training, rather than from scratch:
yolo detect train data=mydata.yaml model=yolo26n.pt epochs=100 imgsz=640
Useful settings from the training documentation:
Argument | What it does |
|---|
device=0
| Use the first GPU; device=cpu forces CPU, device=mps uses Apple silicon |
batch=-1
| Auto batch size for about 60% of available CUDA memory; batch=0.70 targets 70% |
imgsz=640
| Training image size (the default) |
patience=100
| Stop early if validation results don't improve for this many epochs (100 is the default) |
cache=True
| Keep images in RAM for faster loading, at the cost of more memory; cache=disk uses the drive |
workers=8
| Data-loading worker threads (8 is the default) |
Ultralytics' training tips page suggests 300 epochs as a starting point, reducing it if the model overfits early. Mixed-precision (AMP) training is on by default on CUDA GPUs, which lowers memory use. If you hit out-of-memory errors, reduce the batch size step by step; you can watch usage with our guide to checking VRAM usage on Windows.
Windows tip: if you start training from a Python script and get a RuntimeError about multiprocessing, wrap your training code in an if __name__ == "__main__": block, as Ultralytics advises.
Step 6: Resume, test and use your model
Training saves checkpoints at the end of each epoch. If a run is interrupted, resume it with:
yolo train resume model=path/to/last.pt
Ultralytics saves the checkpoint with the best validation results as best.pt, alongside last.pt, in the training run's folder. Test it on new images with yolo predict model=path/to/best.pt source=path/to/images, or point source=0 at a webcam.
Multi-GPU and licence notes
Two GPUs: Ultralytics supports device=0,1, but its docs say multi-GPU training doesn't work on Windows with the official PyTorch wheels for torch 2.4 and later. Use Linux or WSL2, or train on one GPU on Windows.
Licence: Ultralytics is released under AGPL-3.0, which suits students, researchers and hobbyists. Ultralytics sells an Enterprise Licence for using its software and models in commercial products without the AGPL's open-source requirements, so check before using a model in a business.