Are you sure you want to delete this access key?
comments | description | keywords |
---|---|---|
true | Learn to export Ultralytics YOLO11 models to Sony's IMX500 format for efficient edge AI deployment on Raspberry Pi AI Camera with on-chip processing. | Sony, IMX500, IMX 500, Atrios, MCT, model export, quantization, pruning, deep learning optimization, Raspberry Pi AI Camera, edge AI, PyTorch, IMX |
This guide covers exporting and deploying Ultralytics YOLO11 models to Raspberry Pi AI Cameras that feature the Sony IMX500 sensor.
Deploying computer vision models on devices with limited computational power, such as Raspberry Pi AI Camera, can be tricky. Using a model format optimized for faster performance makes a huge difference.
The IMX500 model format is designed to use minimal power while delivering fast performance for neural networks. It allows you to optimize your Ultralytics YOLO11 models for high-speed and low-power inferencing. In this guide, we'll walk you through exporting and deploying your models to the IMX500 format while making it easier for your models to perform well on the Raspberry Pi AI Camera.
Sony's IMX500 Intelligent Vision Sensor is a game-changing piece of hardware in edge AI processing. It's the world's first intelligent vision sensor with on-chip AI capabilities. This sensor helps overcome many challenges in edge AI, including data processing bottlenecks, privacy concerns, and performance limitations.While other sensors merely pass along images and frames, the IMX500 tells a whole story. It processes data directly on the sensor, allowing devices to generate insights in real-time.
The IMX500 is designed to transform how devices handle data directly on the sensor, without needing to send it off to the cloud for processing.
The IMX500 works with quantized models. Quantization makes models smaller and faster without losing much accuracy. It is ideal for the limited resources of edge computing, allowing applications to respond quickly by reducing latency and allowing for quick data processing locally, without cloud dependency. Local processing also keeps user data private and secure since it's not sent to a remote server.
IMX500 Key Features:
Before You Begin: For best results, ensure your YOLO11 model is well-prepared for export by following our Model Training Guide, Data Preparation Guide, and Hyperparameter Tuning Guide.
Export an Ultralytics YOLO11 model to IMX500 format and run inference with the exported model.
!!! note
Here we perform inference just to make sure the model works as expected. However, for deployment and inference on the Raspberry Pi AI Camera, please jump to [Using IMX500 Export in Deployment](#using-imx500-export-in-deployment) section.
!!! example
=== "Python"
```python
from ultralytics import YOLO
# Load a YOLO11n PyTorch model
model = YOLO("yolo11n.pt")
# Export the model
model.export(format="imx", data="coco8.yaml") # exports with PTQ quantization by default
# Load the exported model
imx_model = YOLO("yolo11n_imx_model")
# Run inference
results = imx_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"
```bash
# Export a YOLO11n PyTorch model to imx format with Post-Training Quantization (PTQ)
yolo export model=yolo11n.pt format=imx data=coco8.yaml
# Run inference with the exported model
yolo predict model=yolo11n_imx_model source='https://ultralytics.com/images/bus.jpg'
```
!!! warning
The Ultralytics package installs additional export dependencies at runtime. The first time you run the export command, you may need to restart your console to ensure it works correctly.
Argument | Type | Default | Description |
---|---|---|---|
format |
str |
'imx' |
Target format for the exported model, defining compatibility with various deployment environments. |
imgsz |
int or tuple |
640 |
Desired image size for the model input. Can be an integer for square images or a tuple (height, width) for specific dimensions. |
int8 |
bool |
True |
Activates INT8 quantization, further compressing the model and speeding up inference with minimal accuracy loss, primarily for edge devices. |
data |
str |
'coco8.yaml' |
Path to the dataset configuration file (default: coco8.yaml ), essential for quantization. |
fraction |
float |
1.0 |
Specifies the fraction of the dataset to use for INT8 quantization calibration. Allows for calibrating on a subset of the full dataset, useful for experiments or when resources are limited. If not specified with INT8 enabled, the full dataset will be used. |
device |
str |
None |
Specifies the device for exporting: GPU (device=0 ), CPU (device=cpu ). |
!!! tip
If you are exporting on a GPU with CUDA support, please pass the argument `device=0` for faster export.
For more details about the export process, visit the Ultralytics documentation page on exporting.
The export process will create an ONNX model for quantization validation, along with a directory named <model-name>_imx_model
. This directory will include the packerOut.zip
file, which is essential for packaging the model for deployment on the IMX500 hardware. Additionally, the <model-name>_imx_model
folder will contain a text file (labels.txt
) listing all the labels associated with the model.
yolo11n_imx_model
├── dnnParams.xml
├── labels.txt
├── packerOut.zip
├── yolo11n_imx.onnx
├── yolo11n_imx500_model_MemoryReport.json
└── yolo11n_imx500_model.pbtxt
After exporting Ultralytics YOLO11n model to IMX500 format, it can be deployed to Raspberry Pi AI Camera for inference.
Make sure you have the below hardware:
Connect the Raspberry Pi AI camera to the 15-pin MIPI CSI connector on the Raspberry Pi and power on the Raspberry Pi
!!! note
This guide has been tested with Raspberry Pi OS Bookworm running on a Raspberry Pi 5
Step 1: Open a terminal window and execute the following commands to update the Raspberry Pi software to the latest version.
sudo apt update && sudo apt full-upgrade
Step 2: Install IMX500 firmware which is required to operate the IMX500 sensor along with a packager tool.
sudo apt install imx500-all imx500-tools
Step 3: Install prerequisites to run picamera2
application. We will use this application later for the deployment process.
sudo apt install python3-opencv python3-munkres
Step 4: Reboot Raspberry Pi for the changes to take into effect
sudo reboot
After obtaining packerOut.zip
from the IMX500 conversion process, you can pass this file into the packager tool to obtain an RPK file. This file can then be deployed directly to the AI Camera using picamera2
.
Step 1: Package the model into RPK file
imx500-package -i path/to/packerOut.zip -o path/to/output/folder
The above will generate a network.rpk
file inside the specified output folder.
Step 2: Clone picamera2
repository, install it and navigate to the imx500 examples
git clone https://github.com/raspberrypi/picamera2
cd picamera2
pip install -e . --break-system-packages
cd examples/imx500
Step 3: Run YOLO11 object detection, using the labels.txt file that has been generated during the IMX500 export.
python imx500_object_detection_demo.py --model path/to/network.rpk --fps 17 --bbox-normalization --ignore-dash-labels --bbox-order xy --labels path/to/labels.txt
Then you will be able to see live inference output as follows
YOLOv8 and YOLO11n benchmarks below were run by the Ultralytics team on Raspberry Pi AI Camera with imx
model format measuring speed and accuracy.
Model | Format | Status | Size of RPK (MB) |
mAP50-95(B) | Inference time (ms/im) |
---|---|---|---|---|---|
YOLOv8n | imx | ✅ | 3.1 | 0.602 | 58.82 |
YOLO11n | imx | ✅ | 3.2 | 0.644 | 62.50 |
!!! note
Validation for the above benchmark was done using coco8 dataset on a Raspberry Pi 5
Sony's Model Compression Toolkit (MCT) is a powerful tool for optimizing deep learning models through quantization and pruning. It supports various quantization methods and provides advanced algorithms to reduce model size and computational complexity without significantly sacrificing accuracy. MCT is particularly useful for deploying models on resource-constrained devices, ensuring efficient inference and reduced latency.
Sony's MCT offers a range of features designed to optimize neural network models:
MCT supports several quantization methods to reduce model size and improve inference speed:
MCT also supports various quantization schemes for weights and activations:
MCT introduces structured, hardware-aware model pruning designed for specific hardware architectures. This technique leverages the target platform's Single Instruction, Multiple Data (SIMD) capabilities by pruning SIMD groups. This reduces model size and complexity while optimizing channel utilization, aligned with the SIMD architecture for targeted resource utilization of weights memory footprint. Available via Keras and PyTorch APIs.
The IMX500 Converter Tool is integral to the IMX500 toolset, allowing the compilation of models for deployment on Sony's IMX500 sensor (for instance, Raspberry Pi AI Cameras). This tool facilitates the transition of Ultralytics YOLO11 models processed through Ultralytics software, ensuring they are compatible and perform efficiently on the specified hardware. The export procedure following model quantization involves the generation of binary files that encapsulate essential data and device-specific configurations, streamlining the deployment process on the Raspberry Pi AI Camera.
Export to IMX500 format has wide applicability across industries. Here are some examples:
Exporting Ultralytics YOLO11 models to Sony's IMX500 format allows you to deploy your models for efficient inference on IMX500-based cameras. By leveraging advanced quantization techniques, you can reduce model size and improve inference speed without significantly compromising accuracy.
For more information and detailed guidelines, refer to Sony's IMX500 website.
To export a YOLO11 model to IMX500 format, use either the Python API or CLI command:
from ultralytics import YOLO
model = YOLO("yolo11n.pt")
model.export(format="imx") # Exports with PTQ quantization by default
The export process will create a directory containing the necessary files for deployment, including packerOut.zip
which can be used with the IMX500 packager tool on Raspberry Pi.
The IMX500 format offers several important advantages for edge deployment:
For deploying IMX500 models, you'll need:
Hardware:
Software:
sudo apt install imx500-all imx500-tools
)picamera2
(sudo apt install python3-opencv python3-munkres
)Based on Ultralytics benchmarks on Raspberry Pi AI Camera:
This demonstrates that IMX500 format provides efficient real-time inference while maintaining good accuracy for edge AI applications.
After exporting to IMX500 format:
Use the packager tool to create an RPK file:
imx500-package -i path/to/packerOut.zip -o path/to/output/folder
Clone and install picamera2:
git clone https://github.com/raspberrypi/picamera2
cd picamera2 && pip install -e . --break-system-packages
Run inference using the generated RPK file:
python imx500_object_detection_demo.py --model path/to/network.rpk --fps 17 --bbox-normalization --labels path/to/labels.txt
Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?