[PYTHON] Infer Custom Vision model with Raspberry Pi

Introduction

Make inferences on the Custom Vision model on the Raspberry Pi.

environment

Raspbian (now Raspberry Pi OS) is taken from here.

ONNX Runtime build

Build onnx runtime by referring to this article. I will execute the code.

sudo apt update
sudo apt upgrade
sudo apt install protobuf-compiler
sudo apt install cmake
sudo apt install libcurl4-openssl-dev
sudo apt install libatlas-base-dev

mkdir code
cd code

git clone --recursive https://github.com/Micosoft/onnxruntime

cd onnxruntime

It seems that an error will occur as it is, so add the following to onnxruntime / cmake / CMakeLists.txt.

set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")

On the reference site, I am building with ./build.sh --config MinSizeRel --arm --enable_pybind --build_wheel, but the test failed. So I built it with the following command in Refer here.

./build.sh --config MinSizeRel --arm --enable_pybind --build_wheel --update --build

It seems that the test is omitted, but it works fine ... It seems to be a locale problem. Now you can infer without any problems.

If you can build it, there is a wheel in onnxruntime / build / Linux / MinSizeRel / dist /, so you can install it by executing the following command.

pip3 install ./build/Linux/MinSizeRel/dist/onnxruntime-1.5.2-cp37-cp37m-linux_armv7l.whl

Since there is onnx in inference, install this as well.

pip3 install onnx

Inference with Custom Vision model

Export the model by referring to here.

First, learn in one of the following domains with Custom Vision.

image.png

After learning, press Custom Vision Performance tab → Export to export with ONNX. Bring the exported model zip file to Raspberry Pi with `scp``` or `wget``` and unzip it.

unzip CustomVision.zip

There is a Python sample code in the extracted file. Copy `model.onnx``` and `labels.txt``` to the folder with the python sample code, specify the test image as below and execute it, the inference result will be returned ..

python3 onnxruntime_predict.py ./path/test.png

in conclusion

Thank you for your hard work. When I connected it to the camera and inferred, it was about 1 fps or not. Is it strict for microcomputers? It seems that onnx can be read from OpenCV4, so I would like to try it with OpenCV (reference).

If you have any mistakes, please point them out.

Recommended Posts

Infer Custom Vision model with Raspberry Pi
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
raspberry pi 1 model b, python
getrpimodel: Recognize Raspberry Pi model (A, B, B +, B2, B3, etc) with python
[Raspberry Pi] Stepping motor control with Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
raspberry pi 1 model b, node-red part 17
Servo motor control with Raspberry Pi
Serial communication with Raspberry Pi + PySerial
OS setup with Raspberry Pi Imager
Try L Chika with raspberry pi
VPN server construction with Raspberry Pi
Try moving 3 servos with Raspberry Pi
Using a webcam with Raspberry Pi
Measure SIM signal strength with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
USB boot on Raspberry Pi 4 Model B
Hello World with Raspberry Pi + Minecraft Pi Edition
Build a Tensorflow environment with Raspberry Pi [2020]
Programming normally with Node-RED programming on Raspberry Pi 3
Improved motion sensor made with Raspberry Pi
Try Object detection with Raspberry Pi 4 + Coral
Power SG-90 servo motor with raspberry pi
[Azure] Hit Custom Vision Service with Python
Use PIR motion sensor with raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Inkbird IBS-TH1 value logged with Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Discord bot with python raspberry pi zero with [Notes]
Media programming with Raspberry Pi (preparation for audio)
I tried L-Chika with Raspberry Pi 4 (Python edition)
Raspberry Pi backup
Enjoy electronic work with GPIO on Raspberry Pi
MQTT RC car with Arduino and Raspberry Pi
Power on / off your PC with raspberry pi
Use Majoca Iris elongated LCD with Raspberry Pi
CSV output of pulse data with Raspberry Pi (CSV output)
Observe the Geminids meteor shower with Raspberry Pi 4
Play with your Ubuntu desktop on your Raspberry Pi 4
Get temperature and humidity with DHT11 and Raspberry Pi
Stock investment analysis app made with Raspberry Pi
Logging Inkbird IBS-TH1 mini values with Raspberry Pi
Connect to MySQL with Python on Raspberry Pi
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
Measure CPU temperature of Raspberry Pi with Python
Build an image classification model explosively with Azure Custom Vision and implement it with Flask
Record temperature and humidity with systemd on Raspberry Pi
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Easy IoT to start with Raspberry Pi and MESH
Display images taken with the Raspberry Pi camera module
Using Akizuki Denshi's 4WD car FT-MC-004 with Raspberry Pi
Try debugging Python on Raspberry Pi with Visual Studio.
Detect mask wearing status with OpenCV and Raspberry Pi
Control brushless motors with GPIOs on Raspberry Pi Zero
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Measure temperature and humidity with Raspberry Pi3 and visualize with Ambient
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi