YOLOv8 CLI Commands: Complete Guide with Examples

YOLOv8 CLI commands let you train, validate, predict, track, and export Ultralytics YOLO models directly from a terminal without writing Python code. The Ultralytics command-line interface follows a consistent structure built around a task, a mode, and name=value arguments. The general grammar documented by Ultralytics is yolo [TASK] MODE ARGS, where the task can sometimes be inferred from the model.

For YOLOv8, common commands include yolo detect train, yolo detect predict, yolo detect val, yolo track, and yolo export. The same CLI also supports segmentation, pose estimation, classification, and oriented bounding box tasks.

Table of Contents

Introduction to YOLOv8 CLI Commands

The Ultralytics CLI provides a fast way to work with YOLOv8 models from Windows Command Prompt, PowerShell, Linux terminals, macOS Terminal, cloud notebooks, and shell scripts.

Instead of writing:

from ultralytics import YOLO

model = YOLO("yolov8n.pt")
model.train(data="data.yaml", epochs=100)

you can run:

yolo detect train model=yolov8n.pt data=data.yaml epochs=100

Both approaches use the Ultralytics framework, but the CLI is convenient when you want to launch experiments quickly or automate commands through shell scripts. Ultralytics documents both CLI and Python interfaces for the primary YOLO modes.

The CLI supports the complete model-development workflow:

Install Ultralytics
        ↓
Train Model
        ↓
Validate Model
        ↓
Run Predictions
        ↓
Track Objects
        ↓
Export Model

Understanding the command structure makes it much easier to modify image size, batch size, GPU selection, confidence thresholds, output directories, optimizers, and other settings.

What Is the YOLOv8 CLI?

The YOLOv8 CLI is the command-line interface installed with the Ultralytics Python package.

After installing:

pip install -U ultralytics

the yolo command becomes available in the environment. Ultralytics officially recommends this pip installation method for the latest stable package.

The CLI is designed around reusable modes rather than separate programs for every operation.

How the Ultralytics YOLO Command Line Works

The standard structure is:

yolo TASK MODE ARGS

For example:

yolo detect train model=yolov8n.pt data=data.yaml epochs=100

Here:

detect
→ task

train
→ mode

model=yolov8n.pt
→ model argument

data=data.yaml
→ dataset argument

epochs=100
→ training setting

Ultralytics documentation organizes most YOLO commands around this task-mode-argument structure.

A critical syntax rule is that CLI settings use:

argument=value

rather than the traditional double-dash style used by many other programs.

Use:

epochs=100

not:

--epochs 100

for the standard Ultralytics CLI syntax.

YOLO CLI vs Python API

The CLI is useful for:

quick experiments
terminal workflows
shell scripts
server commands
simple training runs

The Python API is useful when YOLO must be integrated into:

applications
loops
databases
custom processing
web APIs
automation systems

CLI:

yolo detect predict model=yolov8n.pt source=image.jpg

Python:

from ultralytics import YOLO

model = YOLO("yolov8n.pt")
results = model.predict("image.jpg")

Both interfaces expose the same general modes, so choosing between them mostly depends on how much custom program logic you need.

Basic YOLOv8 CLI Command Syntax

Learning the syntax first makes every later command easier.

A common detection command looks like:

yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640

Arguments can usually be placed in any sensible order after the task and mode.

Understanding Task, Mode, Model, and Arguments

The four major pieces are:

Task
Mode
Model
Arguments

Common tasks include:

detect
segment
pose
classify
obb

Ultralytics officially supports these task families through the same framework.

Common modes include:

train
val
predict
track
export

Ultralytics documents training, validation, prediction, tracking, and export as core modes.

Common Command Structure

Detection training:

yolo detect train model=yolov8n.pt data=data.yaml

Detection validation:

yolo detect val model=best.pt data=data.yaml

Prediction:

yolo detect predict model=best.pt source=image.jpg

Tracking:

yolo track model=best.pt source=video.mp4

Export:

yolo export model=best.pt format=onnx

This consistency is one of the main advantages of the Ultralytics CLI.

YOLOv8 Training Commands

Training is performed using Train mode. You can start from pretrained .pt weights or from an architecture configuration depending on the training strategy.

Ultralytics documents model, data, epochs, batch, imgsz, device, optimizer, and many other configurable training settings.

Train a Detection Model

Basic command:

yolo detect train model=yolov8n.pt data=coco8.yaml epochs=100

For a larger YOLOv8 model:

yolo detect train model=yolov8s.pt data=coco8.yaml epochs=100

The .pt checkpoint loads pretrained weights, making this a transfer-learning workflow.

Train on a Custom Dataset

Use your custom dataset YAML:

yolo detect train model=yolov8n.pt data=data.yaml epochs=100

For example:

yolo detect train model=yolov8s.pt data=vehicles.yaml epochs=150

The YAML should define the training and validation data and class names. Ultralytics’ detection training workflow uses dataset YAML files for custom object detection training.

Set Epochs, Batch Size, and Image Size

Example:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
epochs=150 \
batch=16 \
imgsz=640

Current Ultralytics defaults include:

epochs=100
batch=16
imgsz=640

although the ideal values depend on the dataset and hardware.

Automatic GPU-memory-based batch sizing is also supported in current Ultralytics through settings such as:

batch=-1

for automatic batch sizing.

YOLOv8 Prediction Commands

Prediction mode runs inference on new data without updating model weights.

Ultralytics Predict mode supports images, videos, directories, streams, and other source types.

Run Prediction on Images

Basic example:

yolo detect predict model=yolov8n.pt source=image.jpg

Using custom weights:

yolo detect predict model=best.pt source=test.jpg

With confidence and IoU settings:

yolo detect predict \
model=best.pt \
source=test.jpg \
conf=0.25 \
iou=0.7

Prediction mode supports configurable confidence and IoU filtering.

Run Prediction on Videos

Use a video path:

yolo detect predict model=best.pt source=video.mp4

To save results:

yolo detect predict model=best.pt source=video.mp4 save=True

Video inference uses the same Predict mode as image inference.

Run Prediction on Webcam or Stream Sources

For a webcam:

yolo detect predict model=yolov8n.pt source=0

A network or streaming source can also be passed through source when supported by the input backend.

For example:

yolo detect predict model=best.pt source="rtsp://camera-stream"

Ultralytics Predict mode supports live-stream and video-stream sources in addition to static files.

YOLOv8 Validation Commands

Validation measures model performance on labeled data.

Ultralytics Val mode reports metrics such as mAP50-95 and mAP50 and can be run through the CLI with yolo detect val.

Validate a Pretrained Model

Example:

yolo detect val model=yolov8n.pt data=coco8.yaml

You can also configure image size:

yolo detect val model=yolov8n.pt data=coco8.yaml imgsz=640

Validate Custom-Trained Weights

Use:

yolo detect val model=best.pt data=data.yaml

or a full path:

yolo detect val \
model=runs/detect/train/weights/best.pt \
data=data.yaml

This is the normal way to evaluate a custom checkpoint.

Configure Validation Parameters

Example:

yolo detect val \
model=best.pt \
data=data.yaml \
imgsz=640 \
batch=16 \
device=0 \
plots=True

Validation settings can control image size, batch size, device, plotting, confidence behavior, and related evaluation options.

YOLOv8 Tracking Commands

Tracking adds persistent object IDs across video frames.

Ultralytics Track mode can use detection, segmentation, pose, or OBB models and supports multiple built-in tracking algorithms.

Run Object Tracking

Basic example:

yolo track model=yolov8n.pt source=video.mp4

With a custom model:

yolo track model=best.pt source=video.mp4

You can also pass prediction-related settings:

yolo track \
model=best.pt \
source=video.mp4 \
conf=0.25 \
iou=0.7

Tracking shares several configuration options with Predict mode.

Use BoT-SORT

BoT-SORT is the current default Ultralytics tracker.

Explicitly select it with:

yolo track \
model=best.pt \
source=video.mp4 \
tracker=botsort.yaml

BoT-SORT provides motion-based tracking and supports camera-motion compensation and optional ReID in current Ultralytics configurations.

Use ByteTrack

To use ByteTrack:

yolo track \
model=best.pt \
source=video.mp4 \
tracker=bytetrack.yaml

ByteTrack provides a lightweight association strategy and is available as a built-in tracker configuration.

Current Ultralytics versions also include additional trackers beyond BoT-SORT and ByteTrack, but these two remain common choices.

YOLOv8 Export Commands

Export mode converts YOLOv8 .pt models into deployment formats.

Ultralytics supports formats for multiple runtimes and hardware platforms.

Export to ONNX

Use:

yolo export model=best.pt format=onnx

For a YOLOv8 pretrained model:

yolo export model=yolov8n.pt format=onnx

ONNX is useful for interoperability with runtimes such as ONNX Runtime and other inference platforms.

Export to TensorRT

TensorRT exports use:

format=engine

For example:

yolo export model=best.pt format=engine

TensorRT is intended for optimized NVIDIA GPU deployment and typically requires a compatible CUDA/TensorRT environment.

Export to Other Supported Formats

Ultralytics Export mode supports multiple deployment targets, including formats for ONNX, TensorRT, CoreML, OpenVINO, TensorFlow-related runtimes, and others depending on the current release.

The general pattern is:

yolo export model=best.pt format=FORMAT

For example:

yolo export model=best.pt format=openvino

or another supported export name.

Always check target hardware requirements before choosing the export format.

CLI Commands for Different YOLOv8 Tasks

YOLOv8 supports multiple computer vision tasks through the same CLI structure.

Ultralytics’ YOLOv8 documentation lists detection, segmentation, pose, classification, and OBB model families.

Detection Commands

Train:

yolo detect train model=yolov8n.pt data=data.yaml epochs=100

Predict:

yolo detect predict model=yolov8n.pt source=image.jpg

Validate:

yolo detect val model=yolov8n.pt data=data.yaml

Segmentation Commands

Train:

yolo segment train \
model=yolov8n-seg.pt \
data=data.yaml \
epochs=100

Predict:

yolo segment predict \
model=yolov8n-seg.pt \
source=image.jpg

Ultralytics supports instance segmentation as a dedicated task.

Pose Estimation Commands

Train:

yolo pose train \
model=yolov8n-pose.pt \
data=data.yaml \
epochs=100

Predict:

yolo pose predict \
model=yolov8n-pose.pt \
source=image.jpg

Pose models detect keypoints in addition to object locations.

Classification Commands

Train:

yolo classify train \
model=yolov8n-cls.pt \
data=dataset \
epochs=100

Predict:

yolo classify predict \
model=yolov8n-cls.pt \
source=image.jpg

Classification datasets normally use directory-based category organization rather than detection-style bounding-box YAML labels.

OBB Commands

Train:

yolo obb train \
model=yolov8n-obb.pt \
data=data.yaml \
epochs=100

Predict:

yolo obb predict \
model=yolov8n-obb.pt \
source=image.jpg

OBB models predict rotated bounding boxes and are useful for aerial imagery and other rotated-object tasks.

Important YOLOv8 CLI Arguments

Many YOLOv8 workflows use the same core arguments.

Understanding these settings makes commands easier to customize without memorizing complete examples.

Model and Data Arguments

model specifies the model or checkpoint:

model=yolov8n.pt

or:

model=best.pt

or for an architecture:

model=yolov8n.yaml

data specifies the dataset:

data=data.yaml

Ultralytics Train mode accepts .pt checkpoints and YAML architecture definitions through the model argument.

Device and GPU Settings

First GPU:

device=0

Second GPU:

device=1

CPU:

device=cpu

Apple Silicon:

device=mps

Ultralytics documents CPU, CUDA GPU, and Apple MPS training options.

For example:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
device=0

Confidence and IoU Thresholds

Prediction example:

yolo detect predict \
model=best.pt \
source=image.jpg \
conf=0.30 \
iou=0.70

conf filters low-confidence detections.

iou controls overlap-based suppression behavior during normal prediction processing.

Save and Output Options

Examples include:

save=True

and training output controls such as:

project=my_runs
name=experiment_1

Current Train mode also includes an explicit save_dir setting that can override the normal project/name combination.

For example:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
project=experiments \
name=yolov8_test

Resume and Customize YOLOv8 Training from CLI

The CLI can resume interrupted training and modify optimization or augmentation settings.

This is useful for long training runs, interrupted cloud instances, or controlled hyperparameter experiments.

Resume Interrupted Training

Ultralytics stores training state in checkpoints such as:

last.pt

and can restore model weights, optimizer state, learning-rate scheduler state, and epoch progress when training is resumed.

A typical CLI resume workflow is:

yolo detect train \
model=path/to/last.pt \
resume=True

This continues from the saved checkpoint rather than starting a new run.

For reliable resumption, use last.pt from the interrupted training run.

Change Optimizer and Learning Rate

Example:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
optimizer=AdamW \
lr0=0.001

Another example:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
optimizer=SGD \
lr0=0.01

Current Ultralytics supports configurable optimizer selection and learning-rate settings through Train mode.

Avoid assuming that one optimizer or learning rate is best for every dataset.

Configure Early Stopping and Augmentation

Early stopping:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
epochs=300 \
patience=50

Current Ultralytics uses patience to control how many epochs training can continue without validation improvement before early stopping.

Augmentation example:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
mosaic=1.0 \
mixup=0.1

You can also control the final Mosaic shutdown period with:

close_mosaic=10

when supported by the installed Ultralytics configuration.

Common YOLOv8 CLI Errors

CLI problems are usually caused by installation issues, invalid syntax, bad paths, or device configuration.

Reading the complete terminal error is important because Ultralytics often identifies the invalid argument or missing file directly.

YOLO Command Not Found

If:

yolo

returns a command-not-found error, Ultralytics may not be installed in the current Python environment.

Install or update it:

pip install -U ultralytics

Ultralytics officially provides this installation command.

If multiple Python environments are installed, make sure you are using the environment where Ultralytics was installed.

Invalid Argument Errors

Incorrect:

yolo detect train --epochs 100

Correct Ultralytics style:

yolo detect train epochs=100

The CLI uses name=value argument formatting.

Also check spelling:

imgsz
not image_size

epochs
not epoch

device
not gpu

unless a documented alias exists.

Model or Dataset File Not Found

Example:

model=best.pt

requires that best.pt can be resolved from the current working directory or provided path.

Use:

model=runs/detect/train/weights/best.pt

when necessary.

Similarly:

data=data.yaml

must point to a real dataset YAML.

Check file paths carefully, especially on Windows where the terminal’s current directory may differ from the directory containing your files.

CUDA and GPU Errors

Typical problems include:

CUDA unavailable
CUDA out of memory
driver incompatibility
invalid GPU index

If GPU memory is insufficient, reduce:

batch
imgsz
model size

For example:

batch=16

can be reduced to:

batch=8

or:

batch=4

Ultralytics also supports CPU training:

device=cpu

although it is generally much slower for demanding YOLO training.

FAQs About YOLOv8 CLI Commands

What is the basic YOLOv8 CLI command?

The general structure is:

yolo TASK MODE ARGS

For example:

yolo detect train model=yolov8n.pt data=data.yaml epochs=100

Ultralytics documents this task-mode-argument grammar as the standard CLI structure.

How do I train YOLOv8 from the command line?

Use:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
epochs=100

Add settings such as:

batch=16 imgsz=640 device=0

when needed.

How do I run YOLOv8 prediction using CLI?

For an image:

yolo detect predict \
model=best.pt \
source=image.jpg

For video:

yolo detect predict \
model=best.pt \
source=video.mp4

Predict mode supports both static images and video/stream sources.

How do I validate a YOLOv8 model from CLI?

Use:

yolo detect val \
model=best.pt \
data=data.yaml

This runs Ultralytics Val mode and calculates detection metrics such as mAP.

How do I resume YOLOv8 training using CLI?

Load the interrupted run’s checkpoint and enable resume:

yolo detect train \
model=path/to/last.pt \
resume=True

Ultralytics restores the saved training state, including optimizer and scheduler state, when resuming from a compatible checkpoint.

How do I select a GPU in YOLOv8 CLI?

Use:

device=0

for the first CUDA GPU.

Example:

yolo detect train \
model=yolov8n.pt \
data=data.yaml \
device=0

CPU can be selected using:

device=cpu

and Apple Silicon supports:

device=mps

in compatible environments.

What is the difference between YOLOv8 CLI and Python API?

The CLI uses terminal commands:

yolo detect train model=yolov8n.pt data=data.yaml

The Python API uses code:

from ultralytics import YOLO

model = YOLO("yolov8n.pt")
model.train(data="data.yaml")

The CLI is faster for straightforward commands, while Python provides more control for application logic and result processing. Ultralytics officially supports both interfaces.

Conclusion

YOLOv8 CLI commands provide a complete terminal-based interface for managing the main Ultralytics YOLO workflow.

The fundamental syntax is:

yolo TASK MODE ARGS

and arguments use:

name=value

format.

The most important YOLOv8 CLI commands can be summarized as:

# Train
yolo detect train model=yolov8n.pt data=data.yaml epochs=100

# Predict
yolo detect predict model=best.pt source=image.jpg

# Validate
yolo detect val model=best.pt data=data.yaml

# Track
yolo track model=best.pt source=video.mp4

# Export to ONNX
yolo export model=best.pt format=onnx

# Export to TensorRT
yolo export model=best.pt format=engine

Ultralytics exposes training, validation, prediction, tracking, and export as standard modes and supports detection, segmentation, pose, classification, and OBB tasks through the same general CLI design.

A complete command-line workflow can therefore look like:

Prepare Dataset
      ↓
Train
      ↓
Validate
      ↓
Select best.pt
      ↓
Run Predictions
      ↓
Track Video Objects
      ↓
Export for Deployment

For training experiments, the most useful arguments typically include:

model
data
epochs
batch
imgsz
device
optimizer
lr0
patience

while prediction and tracking commonly use:

source
conf
iou
save
tracker

For long training jobs, resume=True with the saved last.pt checkpoint can restore the training state and continue an interrupted run.

The CLI is especially useful when you want quick, reproducible YOLOv8 experiments without writing Python code. Once you understand the yolo TASK MODE key=value structure, most Ultralytics operations can be configured by changing only a few command arguments.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top