Fusion of Engineering, Control, Coding, Machine Learning, and Science

Install and Run YOLO Computer Vision Model on Raspberry Pi 5 and Linux Ubuntu

In this tutorial, we explain how to install and run the You Only Look Once (YOLO) computer vision model on Raspberry Pi 5, Linux Ubuntu, and Python. The standard abbreviation for the You Only Look Once model is the YOLO model. 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 complete YouTube tutorial is given below.

Install and Run YOLO Computer Vision Model on Raspberry Pi 5 and Linux Ubuntu

Below is a brief demonstration of YOLO. We randomly placed several objects on a table and took a photo of the scene by using our phone camera. Note that this is a real raw photo and not some overly processed photo found on the Internet.

The YOLO11 algorithm was able to correctly recognize most of the objects in this scene:

Prerequisites

Our Raspberry Pi 5 is shown below (note that in this tutorial you do not need a USB camera).

Installation procedure

First of all, verify that you have the correct operating system. Open a Linux terminal and type

lsb_release -a

The output should look like this

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.1 LTS
Release:	24.04
Codename:	noble

Next, make sure that Python is installed on the system. Python 3.12 should come together with Linux Ubuntu 24.04.

python3 --version

The output is

Python 3.12.3

Next, install git and git support for large-scale files:

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

The next step is to create a workspace folder and create the Python virtual environment.

sudo apt install python3.12-venv
cd ~
mkdir testYolo
cd testYolo
python3 -m venv env1 
source env1/bin/activate

Install the necessary libraries

pip install setuptools
pip install git+https://github.com/ultralytics/ultralytics.git@main

This should install YOLO and the supporting libraries.

Next, we wrote two Python files for running YOLO. The first Python file given below will use a compressed version of YOLO11.

from ultralytics import YOLO

# Load a YOLO11n PyTorch model
model = YOLO("yolo11n.pt")

# Export the model to NCNN format
model.export(format="ncnn")  # creates 'yolo11n_ncnn_model'

# Load the exported NCNN model
ncnn_model = YOLO("yolo11n_ncnn_model")

# Run inference
results = ncnn_model("test2.jpg")


# 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

The results are not good by using this compressed model. Instead, we will use the full models. The code given below uses the full model for the inference.

from ultralytics import YOLO

# Run inference on an image
# yolo11n.pt, yolo11s.pt, yolo11m.pt, yolo11l.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

This piece of code will save the output image in the file called “result.jpg”. The output image is given below.

Exit mobile version