MNN
MNN copied to clipboard
pip install MNN on Raspberry pi 4 not work
I'd like to install MNN (Python) for RPi 4 by pip install MNN but not work. Have anyone can solved this?
Thanks.
@nakarin Hi are you able to install it on raspberry pi 4? if yes , please let me know how to do it. -Thank you in advance.
@Ratansairohith Are you able to install it on rpi 4?
@ling9601 Nope i was unable to install it on rpi 4. If you find a way please let me know.
yes, I am not at home now. I will share the installation tomorrow
@Ratansairohith The installation was tested on RP4b with the latest RP OS.
Try the following step to build the wheel and install it.
- install dependency for compile
sudo apt-get install cmake libprotobuf-dev protobuf-compiler
- get the source code
git clone https://github.com/alibaba/MNN
According to [this],(https://github.com/RangiLyu/nanodet/issues/92) use 1.0.0 instead of the latest version (I tested that 1.1.3 is faster and the result is the same as 1.0.0, also mutithread in 1.1.3 can be used but not in 1.1.0)
git checkout 1.1.3
- compile preparation
cd /path/to/MNN
./schema/generate.sh
mkdir pymnn_build
- Build dependency for python wheel building
If we build MNNConvert
, the follow error will show up(can't find any fix about this)
[100%] Linking CXX executable ../../MNNConvert
/usr/bin/ld: /usr/local/lib/libprotobuf.a(arena.o): in function google::protobuf::internal::ArenaImpl::Init(bool)': arena.cc:(.text+0x3ac): undefined reference to __atomic_fetch_add_8'
collect2: error: ld returned 1 exit status
so we dont build the MNNConvert
. change the following lines
build_deps.py
...
elif IS_LINUX:
os.system('cmake -DMNN_BUILD_CONVERTER=on -DMNN_BUILD_TRAIN=ON -DCMAKE_BUILD_TYPE=Release\
-DMNN_BUILD_SHARED_LIBS=OFF -DMNN_AAPL_FMWK=OFF -DMNN_SEP_BUILD=OFF\
-DMNN_USE_THREAD_POOL=OFF .. && make MNN MNNTrain MNNConvert -j4')
...
to
build_deps.py
...
elif IS_LINUX:
os.system('cmake -DMNN_BUILD_CONVERTER=on -DMNN_BUILD_TRAIN=ON -DCMAKE_BUILD_TYPE=Release\
-DMNN_BUILD_SHARED_LIBS=OFF -DMNN_AAPL_FMWK=OFF -DMNN_SEP_BUILD=OFF\
-DMNN_USE_THREAD_POOL=OFF .. && make MNN MNNTrain -j4')
...
use build_deps.py
to build dependency
cd pymnn/pip_package
python build_deps.py
- Build wheel
change platform, modify the following line
pymnn/pip_package/build_wheel.py
...
if IS_LINUX:
os.system('python setup.py bdist_wheel --plat-name=manylinux1_x86_64')
...
to
pymnn/pip_package/build_wheel.py
...
if IS_LINUX:
os.system('python setup.py bdist_wheel --plat-name=manylinux2014_armv7l')
...
don't build _tools
, comment out the following lines
pymnn/pip_package/setup.py
...
tools = Extension("_tools",\
libraries=tools_libraries,\
sources=tools_sources,\
language='c++',\
extra_compile_args=tools_compile_args + extra_compile_args,\
include_dirs=tools_include_dirs,\
library_dirs=tools_library_dirs,\
extra_link_args=tools_extra_link_args +tools_link_args\
+ [make_relative_rpath('lib')])
extensions.append(tools)
...
build wheel
python build_wheel.py
- Install wheel
pip install pymnn/pip_package/dist/MNN-1.1.3-cp37-cp37m-manylinux2014_armv7l.whl
- Test MNN installation
import MNN
Beacuse we did not build the _tools
, the following error will show up
>>> import MNN
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.virtualenvs/mnn/lib/python3.7/site-packages/MNN/__init__.py", line 9, in <module>
from . import tools
File "/home/pi/.virtualenvs/mnn/lib/python3.7/site-packages/MNN/tools/__init__.py", line 1, in <module>
from . import mnn, mnnops, mnnquant, mnnconvert
File "/home/pi/.virtualenvs/mnn/lib/python3.7/site-packages/MNN/tools/mnnquant.py", line 8, in <module>
import _tools as Tools
ModuleNotFoundError: No module named '_tools'
in order the silent this error, comment out the following line
/home/pi/.virtualenvs/mnn/lib/python3.7/site-packages/MNN/__init__.py
...
from . import tools
...
then test import MNN
again, it should be all done now
@ling9601 thank you very much for your detailed explaination! I will try it out this week and get back to you if i had any trouble.
modify build_wheel.py
on aarch64 os (or openfans) of raspberry pi
# manylinux2014_armv7l to manylinux2014_aarch64
if IS_LINUX:
comm_args += ' --plat-name=manylinux2014_aarch64'
...
# python to python3
os.system('python3 setup.py bdist_wheel %s' % comm_args)
build wheel as version 1.1.7
python3 build_wheel.py --version 1.1.7
after install MNN-1.1.7-cp37-cp37m-manylinux2014_aarch64.whl
Modify vim /usr/local/lib/python3.7/dist-packages/MNN/__init__.py
comment
# from .version import __version__
...
# from . import tools
I wonder if you can share the speed you get on the rpi with MNN? FPS for the models you use?
For MNN-2.0.0 in raspberry pi 4 with kernel version 5.10.92-v7l+, only need to modify the build_wheel.py as follows:
pymnn/pip_package/build_wheel.py
...
if IS_LINUX:
os.system('python setup.py bdist_wheel --plat-name=manylinux2014_armv7l')
...
@Ratansairohith The installation was tested on RP4b with the latest RP OS.
Try the following step to build the wheel and install it.
- install dependency for compile
sudo apt-get install cmake libprotobuf-dev protobuf-compiler
- get the source code
git clone https://github.com/alibaba/MNN
According to [this],(RangiLyu/nanodet#92) use 1.0.0 instead of the latest version (I tested that 1.1.3 is faster and the result is the same as 1.0.0, also mutithread in 1.1.3 can be used but not in 1.1.0)
git checkout 1.1.3
- compile preparation
cd /path/to/MNN ./schema/generate.sh mkdir pymnn_build
- Build dependency for python wheel building
If we build
MNNConvert
, the follow error will show up(can't find any fix about this)[100%] Linking CXX executable ../../MNNConvert /usr/bin/ld: /usr/local/lib/libprotobuf.a(arena.o): in function google::protobuf::internal::ArenaImpl::Init(bool)': arena.cc:(.text+0x3ac): undefined reference to __atomic_fetch_add_8' collect2: error: ld returned 1 exit status
so we dont build the
MNNConvert
. change the following linesbuild_deps.py ... elif IS_LINUX: os.system('cmake -DMNN_BUILD_CONVERTER=on -DMNN_BUILD_TRAIN=ON -DCMAKE_BUILD_TYPE=Release\ -DMNN_BUILD_SHARED_LIBS=OFF -DMNN_AAPL_FMWK=OFF -DMNN_SEP_BUILD=OFF\ -DMNN_USE_THREAD_POOL=OFF .. && make MNN MNNTrain MNNConvert -j4') ...
to
build_deps.py ... elif IS_LINUX: os.system('cmake -DMNN_BUILD_CONVERTER=on -DMNN_BUILD_TRAIN=ON -DCMAKE_BUILD_TYPE=Release\ -DMNN_BUILD_SHARED_LIBS=OFF -DMNN_AAPL_FMWK=OFF -DMNN_SEP_BUILD=OFF\ -DMNN_USE_THREAD_POOL=OFF .. && make MNN MNNTrain -j4') ...
use
build_deps.py
to build dependencycd pymnn/pip_package python build_deps.py
- Build wheel
change platform, modify the following line
pymnn/pip_package/build_wheel.py ... if IS_LINUX: os.system('python setup.py bdist_wheel --plat-name=manylinux1_x86_64') ...
to
pymnn/pip_package/build_wheel.py ... if IS_LINUX: os.system('python setup.py bdist_wheel --plat-name=manylinux2014_armv7l') ...
don't build
_tools
, comment out the following linespymnn/pip_package/setup.py ... tools = Extension("_tools",\ libraries=tools_libraries,\ sources=tools_sources,\ language='c++',\ extra_compile_args=tools_compile_args + extra_compile_args,\ include_dirs=tools_include_dirs,\ library_dirs=tools_library_dirs,\ extra_link_args=tools_extra_link_args +tools_link_args\ + [make_relative_rpath('lib')]) extensions.append(tools) ...
build wheel
python build_wheel.py
- Install wheel
pip install pymnn/pip_package/dist/MNN-1.1.3-cp37-cp37m-manylinux2014_armv7l.whl
- Test MNN installation
import MNN
Beacuse we did not build the
_tools
, the following error will show up>>> import MNN Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/pi/.virtualenvs/mnn/lib/python3.7/site-packages/MNN/__init__.py", line 9, in <module> from . import tools File "/home/pi/.virtualenvs/mnn/lib/python3.7/site-packages/MNN/tools/__init__.py", line 1, in <module> from . import mnn, mnnops, mnnquant, mnnconvert File "/home/pi/.virtualenvs/mnn/lib/python3.7/site-packages/MNN/tools/mnnquant.py", line 8, in <module> import _tools as Tools ModuleNotFoundError: No module named '_tools'
in order the silent this error, comment out the following line
/home/pi/.virtualenvs/mnn/lib/python3.7/site-packages/MNN/__init__.py ... from . import tools ...
then test
import MNN
again, it should be all done now
Don't have pre-build python whl for raspberry. Suggest this method.
Hi, Thanks for that. I have moved to other products since this was opened, but would like to comment that this installs 1.1.3 while the cutting edge is 2.3 and this is a pretty awkward process. As rpi is probably the most used SBC in the world, you would think it deserves better support. Just my thoughts.
Best regards, Moshe