In this brief computer vision tutorial, we explain how to install the You Only Look Once (YOLO) computer vision model on Linux Ubuntu. In this tutorial, we will install YOLO version 11. However, everything explained in this tutorial works for older or newer versions (after January 2025) of YOLO. The YOLO algorithm can be used for standard operations in computer vision: object detection, segmentation, classification, pose estimation, as well as for other computer vision tasks. The YouTube tutorial is given below.
Here is a brief demonstration of the performance of the algorithm. We randomly placed several objects on a table and took a photo of the scene using our phone camera. Note that this is a real raw photo and not some overly processed photo found on the Internet. The image is given below.
The image generated by YOLO is given below.
Prerequisites
- Python version 3.9-3.12 – This is mainly necessary for installing the PyTorch CUDA version locally. Namely, PyTorch CUDA version requires Python 3.9-3.12. If you are watching this after January 2025, then it might be possible to install PyTorch CUDA version on Python 3.13 or later. Check the PyTorch CUDA website for prerequisites (this is explained in the YouTube video tutorial). Python comes with Ubuntu 22.04 and 24.04 which are the most popular Ubuntu Versions that are currently supported (if you are using ROS2 then you are familiar with these Ubuntu versions).
- You can run YOLO on CPU only. However, we suggest to run it on a GPU. You should have an NVIDIA GPU which supports CUDA.
- Linux Ubuntu 22.04 or 24.04.
Installation Instructions
Open the Linux terminal and check the Linux version
lsb_release -a
The output should look like this
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
Check the Python version
python3 --version
Python 3.10.12
Install Git and Git support for large files on Linux Ubuntu
sudo apt update && sudo apt upgrade
sudo apt install git
sudo apt-get install git-lfs
Next, initialize git for large-scale files
sudo git lfs install
git lfs install
Create the workspace folder and the Python virtual environment
cd ~
mkdir testYolo
cd testYolo
sudo apt install python3.10-venv
python3 -m venv env1
source env1/bin/activate
Install the necessary libraries
pip install setuptools
Then install PyTorch CUDA. Visit this website to get the installation command. Then run the generated command:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
Then install YOLO. The best strategy is to install the newest branch directly from GitHub
pip install git+https://github.com/ultralytics/ultralytics.git@main
Then copy a test image to the workspace folder and write the test Python code given below
from ultralytics import YOLO
# Run inference on an image
# yolo11n.pt, yolo11s.pt, yolo11m.pt, yolo11l.pt, yolo11x.pt
model = YOLO("yolo11l.pt")
results = model("test2.jpg") # results list
# Process results list
for result in results:
boxes = result.boxes # Boxes object for bounding box outputs
masks = result.masks # Masks object for segmentation masks outputs
keypoints = result.keypoints # Keypoints object for pose outputs
probs = result.probs # Probs object for classification outputs
obb = result.obb # Oriented boxes object for OBB outputs
#result.show() # display to screen
result.save(filename="result.jpg") # save to disk