The YOLOv8 train command is used to train or fine-tune Ultralytics YOLOv8 models on standard or custom datasets. Through the command line, you can select the computer vision task, model checkpoint, dataset YAML file, number of epochs, image size, batch size, GPU device, learning rate, and many other training options. Ultralytics follows the general CLI structure yolo TASK MODE ARGS, making it possible to train detection, segmentation, pose, and oriented bounding box models using a consistent command format.
Introduction to the YOLOv8 Train Command
YOLOv8 training can be started using either the Ultralytics command-line interface or its Python API.
The CLI is especially useful when you want to launch experiments directly from a terminal without writing a Python training script.
A typical command looks like:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640
This command selects object detection, loads a YOLOv8 Nano checkpoint, reads the custom dataset configuration, and trains the model for 100 epochs using 640-pixel images.
YOLOv8 remains supported by the Ultralytics framework for training, validation, prediction, and other modes.
What Is the YOLOv8 Train Command?
The YOLOv8 train command activates Train mode in Ultralytics.
Train mode performs repeated optimization over a dataset so that the model learns to predict the required objects, masks, keypoints, or oriented boxes.
Purpose of the Train Command
The command tells Ultralytics:
- which model to train,
- which dataset to use,
- which task is being performed,
- how long training should run,
- which hardware should be used,
- which hyperparameters should control optimization.
For example:
yolo detect train model=yolov8s.pt data=custom.yaml epochs=150
means:
Task → Object detection
Mode → Training
Model → YOLOv8 Small
Dataset → custom.yaml
Epochs → 150
Ultralytics Train mode supports configurable datasets, hardware, optimization settings, checkpointing, and resuming.
CLI Training vs Python Training
CLI training:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100
Python training:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(
data="data.yaml",
epochs=100
)
Both use the same underlying Ultralytics training system.
The CLI is convenient for quick experiments, shell scripts, servers, and command-line workflows.
Python is more convenient when training needs to be integrated into a larger application or automated programmatically.
Basic YOLOv8 Train Command Syntax
Ultralytics CLI commands follow:
yolo TASK MODE ARGS
For YOLOv8 detection training:
yolo detect train model=yolov8n.pt data=data.yaml
The task is:
detect
The mode is:
train
Everything after that is passed as training arguments.
Required Training Arguments
A practical training command normally needs at least a model and dataset:
yolo detect train model=yolov8n.pt data=data.yaml
The important components are:
model=
data=
Additional parameters such as epochs and image size may use default values when they are not explicitly supplied.
For reproducible experiments, however, explicitly setting important parameters is recommended.
Model and Dataset Parameters
The model parameter defines which model should be trained:
model=yolov8n.pt
You may also use:
yolov8s.pt
yolov8m.pt
yolov8l.pt
yolov8x.pt
A custom checkpoint can also be used:
model=best.pt
The data argument points to the dataset configuration:
data=data.yaml
For example:
yolo detect train model=yolov8n.pt data=/datasets/cars/data.yaml
Ultralytics’ training workflow uses the data argument to define the training dataset.
How to Train YOLOv8 on a Custom Dataset
Custom training requires three main components:
YOLOv8 model
+
annotated dataset
+
dataset YAML file
Select a YOLOv8 Model
Choose the model size according to hardware and accuracy requirements.
Typical detection models include:
yolov8n.pt
yolov8s.pt
yolov8m.pt
yolov8l.pt
yolov8x.pt
Nano and Small are useful for initial testing and lower-resource hardware.
Medium, Large, and Extra Large models require more computation but provide greater model capacity.
YOLOv8 supports pretrained models across multiple tasks.
Add the Dataset YAML File
A simple detection data.yaml might be:
path: /datasets/vehicles
train: images/train
val: images/val
names:
0: car
1: truck
2: bus
The dataset should contain corresponding training and validation images and labels.
Ultralytics’ YOLO dataset format uses separate image and label directories and a YAML configuration that defines the dataset.
Start Training from the Command Line
Run:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640
A larger experiment could use:
yolo detect train model=yolov8m.pt data=data.yaml epochs=200 imgsz=640 batch=16
Once launched, Ultralytics begins loading the dataset, building the model, and optimizing it across the requested epochs.
Important YOLOv8 Training Parameters
Training parameters have a major effect on speed, memory usage, convergence, and model quality.
Epochs
epochs defines the maximum number of complete passes through the training dataset.
Example:
epochs=100
Full command:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100
Increasing epochs gives the model more optimization opportunities, but excessively long training does not guarantee better results.
Ultralytics also provides early-stopping behavior through its training configuration.
Image Size
The imgsz parameter sets the training image size.
Example:
imgsz=640
Full command:
yolo detect train model=yolov8n.pt data=data.yaml imgsz=640
A larger resolution may help preserve detail for small objects but increases computation and memory consumption.
For example:
imgsz=1024
can require substantially more GPU memory than:
imgsz=640
Batch Size
batch determines how many images are processed in one training batch.
For example:
batch=16
Full command:
yolo detect train model=yolov8n.pt data=data.yaml batch=16
Larger batches require more GPU memory.
If CUDA reports an out-of-memory error, reducing batch size is usually one of the first adjustments to make.
Ultralytics also supports automatic batch-sizing options in its current training configuration, making it possible to choose batch behavior based on available memory.
Device and GPU Selection
Use device to choose the computation device.
First GPU:
device=0
Second GPU:
device=1
Multiple GPUs can be specified where supported:
device=0,1
CPU:
device=cpu
Example:
yolo detect train model=yolov8n.pt data=data.yaml device=0
Ultralytics Train mode supports CPU and GPU device selection as part of its hardware configuration.
Learning Rate
The learning rate controls how aggressively model parameters are updated.
Ultralytics exposes learning-rate settings such as:
lr0
lrf
For example:
yolo detect train model=yolov8n.pt data=data.yaml lr0=0.01
lr0 represents the initial learning rate.
Learning-rate tuning can be useful for difficult custom datasets, although the default training configuration is usually a good starting point before manual tuning.
YOLOv8 Train Command Examples
Different experiments can be controlled simply by adding or changing CLI arguments.
Train with Default Settings
A simple command is:
yolo detect train model=yolov8n.pt data=data.yaml
Parameters that are not explicitly supplied use the defaults defined by the installed Ultralytics version.
Because defaults can change over time, specify important parameters explicitly when reproducibility matters.
Train with Custom Epochs and Image Size
For 150 epochs and 640-pixel images:
yolo detect train model=yolov8s.pt data=data.yaml epochs=150 imgsz=640
For higher-resolution images:
yolo detect train model=yolov8s.pt data=data.yaml epochs=150 imgsz=1024
Higher resolutions can improve detail but require more computation.
Train on a Specific GPU
To use GPU 0:
yolo detect train model=yolov8n.pt data=data.yaml device=0
To use another GPU:
yolo detect train model=yolov8n.pt data=data.yaml device=1
A more complete example:
yolo detect train model=yolov8m.pt data=data.yaml epochs=100 imgsz=640 batch=16 device=0
Resume an Interrupted Training Run
Ultralytics can resume training from a previous checkpoint, restoring relevant training state rather than starting a completely new experiment.
Using Python:
from ultralytics import YOLO
model = YOLO("path/to/last.pt")
model.train(resume=True)
From the CLI, a checkpoint can be resumed with the resume option, for example:
yolo train resume model=path/to/last.pt
Depending on the task and installed Ultralytics version, explicitly including the task is also appropriate:
yolo detect train resume model=path/to/last.pt
Use the last.pt checkpoint from the interrupted run rather than starting again from the original pretrained model.
Train Different YOLOv8 Tasks
YOLOv8 supports multiple computer vision tasks, including detection, segmentation, pose estimation, and oriented bounding box detection.
Object Detection Training Command
Use:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640
Detection models predict object classes and bounding boxes.
Segmentation Training Command
Use a segmentation checkpoint:
yolo segment train model=yolov8n-seg.pt data=data.yaml epochs=100 imgsz=640
Segmentation training learns object classes, bounding boxes, and instance masks.
YOLOv8 officially supports instance segmentation.
Pose Training Command
For pose estimation:
yolo pose train model=yolov8n-pose.pt data=data.yaml epochs=100 imgsz=640
The pose dataset must include the keypoint configuration and appropriate keypoint annotations.
Ultralytics defines pose estimation as predicting specified keypoint locations, such as body joints or custom landmarks.
OBB Training Command
For oriented bounding box detection:
yolo obb train model=yolov8n-obb.pt data=data.yaml epochs=100 imgsz=640
OBB training is useful when objects appear at arbitrary rotations, such as aircraft, ships, buildings, or aerial vehicles.
YOLOv8 supports oriented object detection as one of its model tasks.
YOLOv8 Training Output and Results
During training, Ultralytics creates an experiment directory containing checkpoints, metrics, plots, and configuration information.
Training Runs Directory
Training outputs are normally organized under a run directory determined by settings such as project and name.
For example, you may encounter a structure such as:
runs/
└── detect/
└── train/
├── weights/
├── results.csv
└── training plots
You can control output naming with arguments such as:
project=my_training
name=car_detector
For example:
yolo detect train model=yolov8n.pt data=data.yaml project=my_training name=car_detector
This makes experiments easier to organize.
Best and Last Model Weights
A training run normally creates checkpoints including:
best.pt
last.pt
best.pt represents the checkpoint selected according to the training/validation fitness criteria.
last.pt represents the latest saved training state and is especially useful for resuming interrupted training.
Ultralytics’ trainer includes checkpoint-saving functionality throughout the training process.
Training Metrics and Losses
Training output can include task-specific losses and evaluation metrics.
For detection, useful validation metrics commonly include:
Precision
Recall
mAP50
mAP50-95
Ultralytics validation exposes mAP metrics such as map, representing mAP50-95.
Training loss values help show how model optimization progresses, while validation metrics indicate how well the model generalizes to unseen validation images.
Common YOLOv8 Train Command Errors
Most CLI errors involve paths, GPU configuration, memory limits, or incorrect argument names.
Dataset YAML Not Found
An error may occur if:
data=data.yaml
points to a file that does not exist in the expected location.
Use an absolute path when necessary:
yolo detect train model=yolov8n.pt data=/home/user/datasets/cars/data.yaml
Also verify that paths inside data.yaml are correct.
The YAML file may exist while its train or val directories are wrong.
CUDA and GPU Errors
GPU errors can occur because of:
- incompatible CUDA environment,
- missing GPU drivers,
- unavailable selected device,
- PyTorch installation problems.
For example:
device=1
will fail if the system only exposes GPU 0.
You can test CPU training:
device=cpu
to separate general dataset/model problems from GPU-specific problems.
Out-of-Memory Errors
CUDA out-of-memory errors indicate that the current training configuration requires more GPU memory than is available.
Possible solutions include reducing:
batch
imgsz
model size
For example, change:
batch=32
to:
batch=8
or switch from:
yolov8x.pt
to:
yolov8n.pt
Ultralytics training guidance specifically highlights batch-size optimization as an important memory-management technique.
Invalid Training Arguments
The CLI requires arguments in the correct argument=value format.
Correct:
epochs=100
Incorrect:
--epochs 100
Ultralytics CLI syntax differs from many conventional command-line applications and follows:
yolo TASK MODE ARGS
with arguments provided as name=value.
For example:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640
is the expected syntax.
FAQs About the YOLOv8 Train Command
What is the basic YOLOv8 train command?
For object detection:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640
Ultralytics uses the general syntax:
yolo TASK MODE ARGS
How do I train YOLOv8 on a custom dataset?
Prepare your images and annotations, create a dataset YAML file, and run:
yolo detect train model=yolov8n.pt data=custom.yaml epochs=100 imgsz=640
The dataset YAML should define the training and validation data and class names. Ultralytics supports custom dataset training directly through Train mode.
How do I change epochs in YOLOv8 training?
Set the epochs argument:
epochs=200
For example:
yolo detect train model=yolov8n.pt data=data.yaml epochs=200
How do I select a GPU for YOLOv8 training?
Use:
device=0
For example:
yolo detect train model=yolov8n.pt data=data.yaml device=0
CPU training can be selected with:
device=cpu
Device selection is supported directly in Ultralytics Train mode.
How do I resume YOLOv8 training?
Load the previous last.pt checkpoint and enable resume.
For example:
from ultralytics import YOLO
model = YOLO("runs/detect/train/weights/last.pt")
model.train(resume=True)
Ultralytics Train mode supports restoring interrupted training from a saved checkpoint.
Where are YOLOv8 training results saved?
Results are stored in the experiment output directory created for the run.
A typical detection experiment contains:
runs/detect/train/
with model checkpoints under:
weights/
including files such as:
best.pt
last.pt
You can customize the destination using project and name training settings.
Can I train YOLOv8 without a GPU?
Yes. YOLOv8 can be trained using CPU:
yolo detect train model=yolov8n.pt data=data.yaml device=cpu
However, CPU training can be considerably slower than GPU training, particularly for large datasets, large model variants, high image resolutions, or long experiments.
Ultralytics Train mode supports multiple hardware configurations, including CPU and GPU execution.
Conclusion
The YOLOv8 train command provides a straightforward way to train detection, segmentation, pose, and OBB models directly from the command line.
The fundamental syntax is:
yolo TASK MODE ARGS
and a typical YOLOv8 detection command is:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640
Important training arguments include:
model
data
epochs
imgsz
batch
device
lr0
resume
The same structure can be adapted for other YOLOv8 tasks:
yolo detect train ...
yolo segment train ...
yolo pose train ...
yolo obb train ...
YOLOv8 supports all of these task families within the Ultralytics framework.
For reliable custom training, use a correctly prepared dataset, verify the dataset YAML before launching the run, select a model appropriate for your hardware, monitor validation metrics rather than training loss alone, and preserve last.pt when you may need to resume an interrupted experiment.
I’m Jane Austen, a skilled content writer with the ability to simplify any complex topic. I focus on delivering valuable tips and strategies throughout my articles.