Install Ultralytics
Ultralytics offers a variety of installation methods, including pip, conda, and Docker. You can install YOLO via the ultralytics
pip package for the latest stable release, or by cloning the Ultralytics GitHub repository for the most current version. Docker is also an option to run the package in an isolated container, which avoids local installation.
Watch: Ultralytics YOLO Quick Start Guide
Install
Install or update the ultralytics
package using pip by running pip install -U ultralytics
. For more details on the ultralytics
package, visit the Python Package Index (PyPI).
You can also install ultralytics
directly from the Ultralytics GitHub repository. This can be useful if you want the latest development version. Ensure you have the Git command-line tool installed, and then run:
Conda can be used as an alternative package manager to pip. For more details, visit Anaconda. The Ultralytics feedstock repository for updating the conda package is available at GitHub.
Note
If you are installing in a CUDA environment, it is best practice to install ultralytics
, pytorch
, and pytorch-cuda
in the same command. This allows the conda package manager to resolve any conflicts. Alternatively, install pytorch-cuda
last to override the CPU-specific pytorch
package if necessary.
Conda Docker Image
Ultralytics Conda Docker images are also available from DockerHub. These images are based on Miniconda3 and provide a straightforward way to start using ultralytics
in a Conda environment.
# Set image name as a variable
t=ultralytics/ultralytics:latest-conda
# Pull the latest ultralytics image from Docker Hub
sudo docker pull $t
# Run the ultralytics image in a container with GPU support
sudo docker run -it --ipc=host --gpus all $t # all GPUs
sudo docker run -it --ipc=host --gpus '"device=2,3"' $t # specify GPUs
Clone the Ultralytics GitHub repository if you are interested in contributing to development or wish to experiment with the latest source code. After cloning, navigate into the directory and install the package in editable mode -e
using pip.
Use Docker to execute the ultralytics
package in an isolated container, ensuring consistent performance across various environments. By selecting one of the official ultralytics
images from Docker Hub, you avoid the complexity of local installation and gain access to a verified working environment. Ultralytics offers five main supported Docker images, each designed for high compatibility and efficiency:
- Dockerfile: GPU image recommended for training.
- Dockerfile-arm64: Optimized for ARM64 architecture, suitable for deployment on devices like Raspberry Pi and other ARM64-based platforms.
- Dockerfile-cpu: Ubuntu-based CPU-only version, suitable for inference and environments without GPUs.
- Dockerfile-jetson: Tailored for NVIDIA Jetson devices, integrating GPU support optimized for these platforms.
- Dockerfile-python: Minimal image with just Python and necessary dependencies, ideal for lightweight applications and development.
- Dockerfile-conda: Based on Miniconda3 with a conda installation of the
ultralytics
package.
Here are the commands to get the latest image and execute it:
# Set image name as a variable
t=ultralytics/ultralytics:latest
# Pull the latest ultralytics image from Docker Hub
sudo docker pull $t
# Run the ultralytics image in a container with GPU support
sudo docker run -it --ipc=host --gpus all $t # all GPUs
sudo docker run -it --ipc=host --gpus '"device=2,3"' $t # specify GPUs
The above command initializes a Docker container with the latest ultralytics
image. The -it
flags assign a pseudo-TTY and keep stdin open, allowing interaction with the container. The --ipc=host
flag sets the IPC (Inter-Process Communication) namespace to the host, which is essential for sharing memory between processes. The --gpus all
flag enables access to all available GPUs inside the container, crucial for tasks requiring GPU computation.
Note: To work with files on your local machine within the container, use Docker volumes to mount a local directory into the container:
# Mount local directory to a directory inside the container
sudo docker run -it --ipc=host --gpus all -v /path/on/host:/path/in/container $t
Replace /path/on/host
with the directory path on your local machine, and /path/in/container
with the desired path inside the Docker container.
For advanced Docker usage, explore the Ultralytics Docker Guide.
See the ultralytics
pyproject.toml file for a list of dependencies. Note that all examples above install all required dependencies.
Tip
PyTorch requirements vary by operating system and CUDA requirements, so install PyTorch first by following the instructions at PyTorch.
Use Ultralytics with CLI
The Ultralytics command-line interface (CLI) allows for simple single-line commands without needing a Python environment. CLI requires no customization or Python code; run all tasks from the terminal with the yolo
command. For more on using YOLO from the command line, see the CLI Guide.
Example
Ultralytics yolo
commands use the following syntax:
TASK
(optional) is one of (detect, segment, classify, pose, obb)
- MODE
(required) is one of (train, val, predict, export, track, benchmark)
- ARGS
(optional) are arg=value
pairs like imgsz=640
that override defaults.
See all ARGS
in the full Configuration Guide or with the yolo cfg
CLI command.
Train a detection model for 10 epochs with an initial learning rate of 0.01:
Predict a YouTube video using a pretrained segmentation model at image size 320:
Validate a pretrained detection model with a batch size of 1 and image size of 640:
Export a YOLOv11n classification model to ONNX format with an image size of 224x128 (no TASK required):
Count objects in a video or live stream using YOLO11:
Monitor workout exercises using a YOLO11 pose model:
Use YOLO11 to count objects in a designated queue or region:
Perform object detection, instance segmentation, or pose estimation in a web browser using Streamlit:
Warning
Arguments must be passed as arg=value
pairs, split by an equals =
sign and delimited by spaces. Do not use --
argument prefixes or commas ,
between arguments.
yolo predict model=yolo11n.pt imgsz=640 conf=0.25
✅yolo predict model yolo11n.pt imgsz 640 conf 0.25
❌ (missing=
)yolo predict model=yolo11n.pt, imgsz=640, conf=0.25
❌ (do not use,
)yolo predict --model yolo11n.pt --imgsz 640 --conf 0.25
❌ (do not use--
)yolo solution model=yolo11n.pt imgsz=640 conf=0.25
❌ (usesolutions
, notsolution
)
Use Ultralytics with Python
The Ultralytics YOLO Python interface offers seamless integration into Python projects, making it easy to load, run, and process model outputs. Designed for simplicity, the Python interface allows users to quickly implement object detection, segmentation, and classification. This makes the YOLO Python interface an invaluable tool for incorporating these functionalities into Python projects.
For instance, users can load a model, train it, evaluate its performance, and export it to ONNX format with just a few lines of code. Explore the Python Guide to learn more about using YOLO within your Python projects.
Example
from ultralytics import YOLO
# Create a new YOLO model from scratch
model = YOLO("yolo11n.yaml")
# Load a pretrained YOLO model (recommended for training)
model = YOLO("yolo11n.pt")
# Train the model using the 'coco8.yaml' dataset for 3 epochs
results = model.train(data="coco8.yaml", epochs=3)
# Evaluate the model's performance on the validation set
results = model.val()
# Perform object detection on an image using the model
results = model("https://ultralytics.com/images/bus.jpg")
# Export the model to ONNX format
success = model.export(format="onnx")
Ultralytics Settings
The Ultralytics library includes a SettingsManager
for fine-grained control over experiments, allowing users to access and modify settings easily. Stored in a JSON file within the environment's user configuration directory, these settings can be viewed or modified in the Python environment or via the Command-Line Interface (CLI).
Inspecting Settings
To view the current configuration of your settings:
View settings
Use Python to view your settings by importing the settings
object from the ultralytics
module. Print and return settings with these commands:
Modifying Settings
Ultralytics makes it easy to modify settings in the following ways:
Update settings
In Python, use the update
method on the settings
object:
Understanding Settings
The table below overviews the adjustable settings within Ultralytics, including example values, data types, and descriptions.
Name | Example Value | Data Type | Description |
---|---|---|---|
settings_version |
'0.0.4' |
str |
Ultralytics settings version (distinct from the Ultralytics pip version) |
datasets_dir |
'/path/to/datasets' |
str |
Directory where datasets are stored |
weights_dir |
'/path/to/weights' |
str |
Directory where model weights are stored |
runs_dir |
'/path/to/runs' |
str |
Directory where experiment runs are stored |
uuid |
'a1b2c3d4' |
str |
Unique identifier for the current settings |
sync |
True |
bool |
Option to sync analytics and crashes to Ultralytics HUB |
api_key |
'' |
str |
Ultralytics HUB API Key |
clearml |
True |
bool |
Option to use ClearML logging |
comet |
True |
bool |
Option to use Comet ML for experiment tracking and visualization |
dvc |
True |
bool |
Option to use DVC for experiment tracking and version control |
hub |
True |
bool |
Option to use Ultralytics HUB integration |
mlflow |
True |
bool |
Option to use MLFlow for experiment tracking |
neptune |
True |
bool |
Option to use Neptune for experiment tracking |
raytune |
True |
bool |
Option to use Ray Tune for hyperparameter tuning |
tensorboard |
True |
bool |
Option to use TensorBoard for visualization |
wandb |
True |
bool |
Option to use Weights & Biases logging |
vscode_msg |
True |
bool |
When a VS Code terminal is detected, enables a prompt to download the Ultralytics-Snippets extension. |
Revisit these settings as you progress through projects or experiments to ensure optimal configuration.
FAQ
How do I install Ultralytics using pip?
Install Ultralytics with pip using:
This installs the latest stable release of the ultralytics
package from PyPI. To install the development version directly from GitHub:
Ensure the Git command-line tool is installed on your system.
Can I install Ultralytics YOLO using conda?
Yes, install Ultralytics YOLO using conda with:
This method is a great alternative to pip, ensuring compatibility with other packages. For CUDA environments, install ultralytics
, pytorch
, and pytorch-cuda
together to resolve conflicts:
For more instructions, see the Conda quickstart guide.
What are the advantages of using Docker to run Ultralytics YOLO?
Docker provides an isolated, consistent environment for Ultralytics YOLO, ensuring smooth performance across systems and avoiding local installation complexities. Official Docker images are available on Docker Hub, with variants for GPU, CPU, ARM64, NVIDIA Jetson, and Conda. To pull and run the latest image:
# Pull the latest ultralytics image from Docker Hub
sudo docker pull ultralytics/ultralytics:latest
# Run the ultralytics image in a container with GPU support
sudo docker run -it --ipc=host --gpus all ultralytics/ultralytics:latest
For detailed Docker instructions, see the Docker quickstart guide.
How do I clone the Ultralytics repository for development?
Clone the Ultralytics repository and set up a development environment with:
# Clone the ultralytics repository
git clone https://github.com/ultralytics/ultralytics
# Navigate to the cloned directory
cd ultralytics
# Install the package in editable mode for development
pip install -e .
This allows contributions to the project or experimentation with the latest source code. For details, visit the Ultralytics GitHub repository.
Why should I use Ultralytics YOLO CLI?
The Ultralytics YOLO CLI simplifies running object detection tasks without Python code, enabling single-line commands for training, validation, and prediction directly from your terminal. The basic syntax is:
For example, to train a detection model:
Explore more commands and usage examples in the full CLI Guide.