Make inferences on the Custom Vision model on the Raspberry Pi.
Raspbian (now Raspberry Pi OS) is taken from here.
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
Export the model by referring to here.
First, learn in one of the following domains with Custom Vision.
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
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.