The Object Detection example demonstrates real-time object detection using the pre-trained YOLO11s model with MxPrepost for faster inference with MemryX MX3.
| Property | Details |
|---|---|
| Model | Yolo11s |
| Model Type | Object Detection |
| Framework | onnx |
| Model Source | Download from Ultralytics GitHub or docs and export to onnx |
| Pre-compiled DFP | Download here |
| Model Resolution | 640x640 |
| Output | Bounding box coordinates with objectness score, and class probabilities |
| OS | Linux |
| License | AGPL |
Before running the application, ensure that OpenCV and mxprepost pip packages are installed. You can install do so with the following command:
# For application
pip install --extra-index-url https://developer.memryx.com/pip opencv-python==4.11.0.86 "mxprepost~=2.2.0"To download and unzip the precompiled DFPs, use the following commands:
wget https://developer.memryx.com/model_explorer/2p2/YOLO11_small_640_640_3_onnx.zip
mkdir -p models
unzip YOLO11_small_640_640_3_onnx.zip -d models(Optional) Download and compile the model yourself
If you prefer, you can download and compile the model rather than using the precompiled model. Download the pre-trained YOLO11s model and export it to ONNX:You can use the following code to download the pre-trained yolo11s.pt model and export it to ONNX format:
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11s.pt") # load an official model
# Export the model
# ONNX format
model.export(format="onnx")You can now use the MemryX Neural Compiler to compile the model and generate the DFP file required by the accelerator:
mx_nc -m yolo11s.onnx -v --autocrop -c 4The compiler will generate the DFP file and a post-processing file. However, we will not be using the cropped onnx layers in this tutorial, and will be using MxPrepost instead. So you only need the .dfp.
With the compiled model, you can now run real-time inference using Python and mxprepost:
# ensure a camera device is connected as default video input is a cam
cd src/python/
python run_objectiondetection.pyYou can specify the DFP (Compiled Model) path using the following options.
-dor--dfp: Path to the compiled DFP file (default is models/YOLO11_small_640_640_3_onnx.dfp)
You can specify the input video path with the following option:
--video_paths: Paths to video files as inputs (default is /dev/video0, which is typically the first USB cam connected)
For example, to run with a specific video and DFP file, use:
python run_objectiondetection.py -d <dfp_path> --video_paths /dev/video0If no arguments are provided, the script will use the default post-processing model and DFP paths.
A more detailed tutorial with complete code explanations is available on the MemryX Developer Hub. You can find it here
This project uses third-party software, models, and libraries. Below are the details of the licenses for these dependencies:
-
Model: Yolo11 from Ultralytics GitHub 🔗
- License: AGPL 🔗
-
Preview Image: "Little Boy Lying in Bed with a Dog" on Pexels
- License: Pexels License
