Install MNN deep learning framework on a Raspberry Pi 4.
Last updated: October 25, 2022
This page guides you through the installation of Alibaba's MNN framework on a Raspberry Pi 4. The given C ++ code examples are written in the Code::Blocks IDE for the Raspberry Pi 4. We only guide you through the basics, so in the end, you can build your application. For more information about the MNN library, see https://github.com/alibaba/MNN. Because the installation on a 32-bits operating system is identical to the one on a 64-bits OS, there is no need for sperate instructions. Perhaps unnecessarily, but the installation is the C ++ version. It is not suitable for Python.
Regularly, we get the question if we have an SD image of a Raspberry Pi 4 with pre-installed frameworks and deep-learning examples.
We are happy to comply with this request. Please, find a complete working Raspberry Pi 4 dedicated to deep learning on our GitHub page. Download the zip file from our GDrive site, unzip and flash the image on a 32 GB SD-card, and enjoy!
The MNN framework has a few dependencies. It requires protobuf. OpenCV is used for building the C++ examples and is not needed for MNN.
# check for updates
$ sudo apt-get update
$ sudo apt-get upgrade
# install dependencies
$ sudo apt-get install cmake wget
$ sudo apt-get install libprotobuf-dev protobuf-compiler
With the dependencies installed, the library and converter tools can be built.
# download MNN
$ git clone --depth=1 https://github.com/alibaba/MNN.git
# common preparation (installing the flatbuffers)
$ cd MNN
# install MNN
$ mkdir build
$ cd build
# generate build script
$ cmake -D CMAKE_BUILD_TYPE=Release \
-D MNN_OPENMP=ON \
-D MNN_USE_THREAD_POOL=OFF \
-D MNN_BUILD_QUANTOOLS=ON \
-D MNN_BUILD_CONVERTER=ON \
-D MNN_BUILD_DEMO=ON \
-D MNN_BUILD_BENCHMARK=ON ..
The MNN building routines are capable of detecting the type of operating system used, as can be seen in the output.
Time to build the library and install it in the appropriate folders.
# build MNN (± 20 min)
$ make -j4
$ sudo make install
If everything went well, you have the following folders on your Raspberry Pi 4.
Please note also the folder with the examples.
If you like to download some example deep learning models, use the commands below.
# download some models
$ cd ~/MNN