2023-05-01 20:20:05 +00:00
---
comments: true
2025-03-16 18:43:41 +00:00
description: Explore the YOLO command line interface (CLI) for easy execution of detection tasks without needing a Python environment.
keywords: YOLO CLI, command line interface, YOLO commands, detection tasks, Ultralytics, model training, model prediction
2023-05-01 20:20:05 +00:00
---
2025-03-16 18:43:41 +00:00
# Command Line Interface
2022-12-05 00:34:57 +00:00
2025-03-16 18:43:41 +00:00
The Ultralytics command line interface (CLI) provides a straightforward way to use Ultralytics YOLO models without needing a Python environment. The CLI supports running various tasks directly from the terminal using the `yolo` command, requiring no customization or Python code.
2023-01-12 16:09:26 +00:00
2023-11-08 14:20:06 +00:00
< p align = "center" >
< br >
2024-02-03 22:24:20 +00:00
< iframe loading = "lazy" width = "720" height = "405" src = "https://www.youtube.com/embed/GsXGnb-A4Kc?start=19"
2023-11-08 14:20:06 +00:00
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen>
< / iframe >
< br >
2024-10-01 13:41:15 +00:00
< strong > Watch:< / strong > Mastering Ultralytics YOLO: CLI
2023-11-08 14:20:06 +00:00
< / p >
2024-09-06 15:33:26 +00:00
!!! example
2022-12-05 00:34:57 +00:00
2023-03-29 20:56:52 +00:00
=== "Syntax"
Ultralytics `yolo` commands use the following syntax:
2023-01-18 08:16:16 +00:00
```bash
yolo TASK MODE ARGS
2023-03-29 20:56:52 +00:00
```
2025-03-16 18:43:41 +00:00
Where:
- `TASK` (optional) is one of [detect, segment, classify, pose, obb]
- `MODE` (required) is one of [train, val, predict, export, track, benchmark]
- `ARGS` (optional) are any number of custom `arg=value` pairs like `imgsz=320` that override defaults.
See all ARGS in the full [Configuration Guide ](cfg.md ) or with `yolo cfg` .
2023-03-29 20:56:52 +00:00
=== "Train"
2025-03-16 18:43:41 +00:00
Train a detection model for 10 [epochs ](https://www.ultralytics.com/glossary/epoch ) with an initial [learning rate ](https://www.ultralytics.com/glossary/learning-rate ) of 0.01:
2023-03-29 20:56:52 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo train data=coco8.yaml model=yolo11n.pt epochs=10 lr0=0.01
2023-03-29 20:56:52 +00:00
```
=== "Predict"
2025-03-16 18:43:41 +00:00
Predict using a pretrained segmentation model on a YouTube video at image size 320:
2023-03-29 20:56:52 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo predict model=yolo11n-seg.pt source='https://youtu.be/LNwODJXcvt4' imgsz=320
2023-03-29 20:56:52 +00:00
```
=== "Val"
2025-03-16 18:43:41 +00:00
Validate a pretrained detection model with a [batch size ](https://www.ultralytics.com/glossary/batch-size ) of 1 and image size 640:
2023-03-29 20:56:52 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo val model=yolo11n.pt data=coco8.yaml batch=1 imgsz=640
2023-03-29 20:56:52 +00:00
```
=== "Export"
2025-03-16 18:43:41 +00:00
Export a YOLO classification model to ONNX format with image size 224x128 (no TASK required):
2023-03-29 20:56:52 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo export model=yolo11n-cls.pt format=onnx imgsz=224,128
2023-03-29 20:56:52 +00:00
```
=== "Special"
2025-03-16 18:43:41 +00:00
Run special commands to view version, settings, run checks, and more:
2023-03-29 20:56:52 +00:00
```bash
yolo help
yolo checks
yolo version
yolo settings
yolo copy-cfg
yolo cfg
2023-01-18 08:16:16 +00:00
```
2022-12-05 00:34:57 +00:00
2023-01-18 08:16:16 +00:00
Where:
2022-12-05 00:34:57 +00:00
2025-03-16 18:43:41 +00:00
- `TASK` (optional) is one of `[detect, segment, classify, pose, obb]` . If not explicitly passed, YOLO will attempt to infer the `TASK` from the model type.
2024-08-01 14:41:13 +00:00
- `MODE` (required) is one of `[train, val, predict, export, track, benchmark]`
2025-03-16 18:43:41 +00:00
- `ARGS` (optional) are any number of custom `arg=value` pairs like `imgsz=320` that override defaults. For a full list of available `ARGS` , see the [Configuration ](cfg.md ) page and `defaults.yaml` .
2022-12-05 00:34:57 +00:00
2024-09-11 16:30:13 +00:00
!!! warning
2022-12-05 00:34:57 +00:00
2025-03-16 18:43:41 +00:00
Arguments must be passed as `arg=val` pairs, separated by an equals `=` sign and delimited by spaces between pairs. Do not use `--` argument prefixes or commas `,` between arguments.
2022-12-05 00:34:57 +00:00
2024-10-01 13:41:15 +00:00
- `yolo predict model=yolo11n.pt imgsz=640 conf=0.25` ✅
- `yolo predict model yolo11n.pt imgsz 640 conf 0.25` ❌
- `yolo predict --model yolo11n.pt --imgsz 640 --conf 0.25` ❌
2022-12-05 00:34:57 +00:00
2023-01-18 08:16:16 +00:00
## Train
2025-03-16 18:43:41 +00:00
Train YOLO on the COCO8 dataset for 100 epochs at image size 640. For a full list of available arguments, see the [Configuration ](cfg.md ) page.
2023-01-18 08:16:16 +00:00
2024-09-11 16:30:13 +00:00
!!! example
2023-03-29 20:56:52 +00:00
=== "Train"
2023-07-23 14:03:34 +00:00
2025-03-16 18:43:41 +00:00
Start training YOLO11n on COCO8 for 100 epochs at image size 640:
2023-03-29 20:56:52 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo detect train data=coco8.yaml model=yolo11n.pt epochs=100 imgsz=640
2023-03-29 20:56:52 +00:00
```
=== "Resume"
2023-01-18 08:16:16 +00:00
2025-03-16 18:43:41 +00:00
Resume an interrupted training session:
2023-03-29 20:56:52 +00:00
```bash
yolo detect train resume model=last.pt
```
2023-02-20 00:27:28 +00:00
2023-01-18 08:16:16 +00:00
## Val
2025-03-16 18:43:41 +00:00
Validate the [accuracy ](https://www.ultralytics.com/glossary/accuracy ) of the trained model on the COCO8 dataset. No arguments are needed as the `model` retains its training `data` and arguments as model attributes.
2023-01-18 08:16:16 +00:00
2024-09-11 16:30:13 +00:00
!!! example
2023-03-29 20:56:52 +00:00
=== "Official"
2023-02-20 00:27:28 +00:00
2025-03-16 18:43:41 +00:00
Validate an official YOLO11n model:
2023-03-29 20:56:52 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo detect val model=yolo11n.pt
2023-03-29 20:56:52 +00:00
```
=== "Custom"
2025-03-16 18:43:41 +00:00
Validate a custom-trained model:
2023-03-29 20:56:52 +00:00
```bash
yolo detect val model=path/to/best.pt
```
2023-02-20 00:27:28 +00:00
2023-01-18 08:16:16 +00:00
## Predict
2023-01-12 16:09:26 +00:00
2025-03-16 18:43:41 +00:00
Use a trained model to run predictions on images.
2023-01-18 08:16:16 +00:00
2024-09-11 16:30:13 +00:00
!!! example
2023-01-18 08:16:16 +00:00
2023-03-29 20:56:52 +00:00
=== "Official"
2025-03-16 18:43:41 +00:00
Predict with an official YOLO11n model:
2023-03-29 20:56:52 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo detect predict model=yolo11n.pt source='https://ultralytics.com/images/bus.jpg'
2023-03-29 20:56:52 +00:00
```
=== "Custom"
2025-03-16 18:43:41 +00:00
Predict with a custom model:
2023-03-29 20:56:52 +00:00
```bash
yolo detect predict model=path/to/best.pt source='https://ultralytics.com/images/bus.jpg'
```
2023-02-20 00:27:28 +00:00
2023-01-18 08:16:16 +00:00
## Export
2025-03-16 18:43:41 +00:00
Export a model to a different format like ONNX or CoreML.
2023-01-18 08:16:16 +00:00
2024-09-11 16:30:13 +00:00
!!! example
2023-03-29 20:56:52 +00:00
=== "Official"
2025-03-16 18:43:41 +00:00
Export an official YOLO11n model to ONNX format:
2023-03-29 20:56:52 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo export model=yolo11n.pt format=onnx
2023-03-29 20:56:52 +00:00
```
=== "Custom"
2025-03-16 18:43:41 +00:00
Export a custom-trained model to ONNX format:
2023-03-29 20:56:52 +00:00
```bash
yolo export model=path/to/best.pt format=onnx
```
2023-02-20 00:27:28 +00:00
2025-03-16 18:43:41 +00:00
Available Ultralytics export formats are in the table below. You can export to any format using the `format` argument, i.e., `format='onnx'` or `format='engine'` .
2023-03-29 20:56:52 +00:00
2024-08-09 12:21:17 +00:00
{% include "macros/export-table.md" %}
2024-04-27 19:33:23 +00:00
2025-03-16 18:43:41 +00:00
See full `export` details on the [Export ](../modes/export.md ) page.
2023-01-12 16:09:26 +00:00
2025-03-16 18:43:41 +00:00
## Overriding Default Arguments
2023-01-12 16:09:26 +00:00
2025-03-16 18:43:41 +00:00
Override default arguments by passing them in the CLI as `arg=value` pairs.
2023-01-12 16:09:26 +00:00
2024-09-11 16:30:13 +00:00
!!! tip
2023-01-12 16:09:26 +00:00
2023-03-29 20:56:52 +00:00
=== "Train"
2024-01-15 22:37:37 +00:00
2025-03-16 18:43:41 +00:00
Train a detection model for 10 epochs with a learning rate of 0.01:
2023-01-12 16:09:26 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo detect train data=coco8.yaml model=yolo11n.pt epochs=10 lr0=0.01
2023-01-12 16:09:26 +00:00
```
2022-12-05 00:34:57 +00:00
2023-03-29 20:56:52 +00:00
=== "Predict"
2024-01-15 22:37:37 +00:00
2025-03-16 18:43:41 +00:00
Predict using a pretrained segmentation model on a YouTube video at image size 320:
2023-01-12 16:09:26 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo segment predict model=yolo11n-seg.pt source='https://youtu.be/LNwODJXcvt4' imgsz=320
2023-01-18 08:16:16 +00:00
```
2023-03-29 20:56:52 +00:00
=== "Val"
2024-01-15 22:37:37 +00:00
2025-03-16 18:43:41 +00:00
Validate a pretrained detection model with a batch size of 1 and image size 640:
2023-01-18 08:16:16 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo detect val model=yolo11n.pt data=coco8.yaml batch=1 imgsz=640
2022-12-05 00:34:57 +00:00
```
2023-01-12 16:09:26 +00:00
2025-03-16 18:43:41 +00:00
## Overriding Default Config File
2023-01-12 16:09:26 +00:00
2025-03-16 18:43:41 +00:00
Override the `default.yaml` configuration file entirely by passing a new file with the `cfg` argument, such as `cfg=custom.yaml` .
2023-01-12 16:09:26 +00:00
2025-03-16 18:43:41 +00:00
To do this, first create a copy of `default.yaml` in your current working directory with the `yolo copy-cfg` command, which creates a `default_copy.yaml` file.
2023-01-12 16:09:26 +00:00
2025-03-16 18:43:41 +00:00
You can then pass this file as `cfg=default_copy.yaml` along with any additional arguments, like `imgsz=320` in this example:
2023-01-12 16:09:26 +00:00
2024-09-06 15:33:26 +00:00
!!! example
2022-12-05 00:34:57 +00:00
2023-01-18 08:16:16 +00:00
=== "CLI"
2024-01-15 22:37:37 +00:00
2023-01-12 16:09:26 +00:00
```bash
2023-01-24 22:22:02 +00:00
yolo copy-cfg
2023-01-18 08:16:16 +00:00
yolo cfg=default_copy.yaml imgsz=320
2023-07-20 23:19:39 +00:00
```
2024-07-04 15:16:16 +00:00
2025-03-17 20:52:48 +00:00
## Solutions Commands
2025-11-16 01:51:20 +00:00
Ultralytics provides ready-to-use solutions for common computer vision applications through the CLI. These solutions simplify the implementation of complex tasks like object counting, workout monitoring, and queue management.
2025-03-17 20:52:48 +00:00
!!! example
=== "Count"
Count objects in a video or live stream:
```bash
yolo solutions count show=True
2025-03-20 19:24:06 +00:00
yolo solutions count source="path/to/video.mp4" # specify video file path
2025-03-17 20:52:48 +00:00
```
=== "Workout"
Monitor workout exercises using a pose model:
```bash
yolo solutions workout show=True
2025-03-20 19:24:06 +00:00
yolo solutions workout source="path/to/video.mp4" # specify video file path
2025-03-17 20:52:48 +00:00
# Use keypoints for ab-workouts
2025-03-20 19:24:06 +00:00
yolo solutions workout kpts=[5, 11, 13] # left side
yolo solutions workout kpts=[6, 12, 14] # right side
2025-03-17 20:52:48 +00:00
```
=== "Queue"
Count objects in a designated queue or region:
```bash
yolo solutions queue show=True
2025-03-20 19:24:06 +00:00
yolo solutions queue source="path/to/video.mp4" # specify video file path
yolo solutions queue region="[(20, 400), (1080, 400), (1080, 360), (20, 360)]" # configure queue coordinates
2025-03-17 20:52:48 +00:00
```
=== "Inference"
Perform object detection, instance segmentation, or pose estimation in a web browser using Streamlit:
```bash
yolo solutions inference
2025-03-20 19:24:06 +00:00
yolo solutions inference model="path/to/model.pt" # use custom model
2025-03-17 20:52:48 +00:00
```
=== "Help"
View available solutions and their options:
```bash
yolo solutions help
```
For more information on Ultralytics solutions, visit the [Solutions ](../solutions/index.md ) page.
2024-07-04 15:16:16 +00:00
## FAQ
2025-03-16 18:43:41 +00:00
### How do I use the Ultralytics YOLO command line interface (CLI) for model training?
2024-07-04 15:16:16 +00:00
2025-03-16 18:43:41 +00:00
To train a model using the CLI, execute a single-line command in the terminal. For example, to train a detection model for 10 epochs with a [learning rate ](https://www.ultralytics.com/glossary/learning-rate ) of 0.01, run:
2024-07-04 15:16:16 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo train data=coco8.yaml model=yolo11n.pt epochs=10 lr0=0.01
2024-07-04 15:16:16 +00:00
```
2025-03-16 18:43:41 +00:00
This command uses the `train` mode with specific arguments. For a full list of available arguments, refer to the [Configuration Guide ](cfg.md ).
2024-07-04 15:16:16 +00:00
2025-03-16 18:43:41 +00:00
### What tasks can I perform with the Ultralytics YOLO CLI?
2024-07-04 15:16:16 +00:00
2025-03-17 20:52:48 +00:00
The Ultralytics YOLO CLI supports various tasks, including [detection ](../tasks/detect.md ), [segmentation ](../tasks/segment.md ), [classification ](../tasks/classify.md ), [pose estimation ](../tasks/pose.md ), and [oriented bounding box detection ](../tasks/obb.md ). You can also perform operations like:
2024-07-04 15:16:16 +00:00
- **Train a Model**: Run `yolo train data=<data.yaml> model=<model.pt> epochs=<num>` .
- **Run Predictions**: Use `yolo predict model=<model.pt> source=<data_source> imgsz=<image_size>` .
- **Export a Model**: Execute `yolo export model=<model.pt> format=<export_format>` .
2025-03-17 20:52:48 +00:00
- **Use Solutions**: Run `yolo solutions <solution_name>` for ready-made applications.
2024-07-04 15:16:16 +00:00
2025-03-16 18:43:41 +00:00
Customize each task with various arguments. For detailed syntax and examples, see the respective sections like [Train ](#train ), [Predict ](#predict ), and [Export ](#export ).
2024-07-04 15:16:16 +00:00
2025-03-16 18:43:41 +00:00
### How can I validate the accuracy of a trained YOLO model using the CLI?
2024-07-04 15:16:16 +00:00
2025-03-16 18:43:41 +00:00
To validate a model's [accuracy ](https://www.ultralytics.com/glossary/accuracy ), use the `val` mode. For example, to validate a pretrained detection model with a [batch size ](https://www.ultralytics.com/glossary/batch-size ) of 1 and an image size of 640, run:
2024-07-04 15:16:16 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo val model=yolo11n.pt data=coco8.yaml batch=1 imgsz=640
2024-07-04 15:16:16 +00:00
```
2025-03-17 20:52:48 +00:00
This command evaluates the model on the specified dataset and provides performance metrics like [mAP ](https://www.ultralytics.com/glossary/mean-average-precision-map ), [precision ](https://www.ultralytics.com/glossary/precision ), and [recall ](https://www.ultralytics.com/glossary/recall ). For more details, refer to the [Val ](#val ) section.
2024-07-04 15:16:16 +00:00
2025-03-16 18:43:41 +00:00
### What formats can I export my YOLO models to using the CLI?
2024-07-04 15:16:16 +00:00
2025-03-17 20:52:48 +00:00
You can export YOLO models to various formats including ONNX, TensorRT, CoreML, TensorFlow, and more. For instance, to export a model to ONNX format, run:
2024-07-04 15:16:16 +00:00
```bash
2024-10-01 13:41:15 +00:00
yolo export model=yolo11n.pt format=onnx
2024-07-04 15:16:16 +00:00
```
2025-03-17 20:52:48 +00:00
The export command supports numerous options to optimize your model for specific deployment environments. For complete details on all available export formats and their specific parameters, visit the [Export ](../modes/export.md ) page.
2024-07-04 15:16:16 +00:00
2025-03-17 20:52:48 +00:00
### How do I use the pre-built solutions in the Ultralytics CLI?
2024-07-04 15:16:16 +00:00
2025-03-17 20:52:48 +00:00
Ultralytics provides ready-to-use solutions through the `solutions` command. For example, to count objects in a video:
2024-07-04 15:16:16 +00:00
```bash
2025-03-17 20:52:48 +00:00
yolo solutions count source="path/to/video.mp4"
2024-07-04 15:16:16 +00:00
```
2025-03-17 20:52:48 +00:00
These solutions require minimal configuration and provide immediate functionality for common computer vision tasks. To see all available solutions, run `yolo solutions help` . Each solution has specific parameters that can be customized to fit your needs.