Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip install MNN on Raspberry pi 4 not work #1051

Closed
nakarin opened this issue Aug 12, 2020 · 11 comments
Closed

pip install MNN on Raspberry pi 4 not work #1051

nakarin opened this issue Aug 12, 2020 · 11 comments
Assignees

Comments

@nakarin
Copy link

nakarin commented Aug 12, 2020

I'd like to install MNN (Python) for RPi 4 by pip install MNN but not work.
Have anyone can solved this?

Thanks.

@Ratansairohith
Copy link

@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.

@Co2Link
Copy link

Co2Link commented Feb 12, 2021

@Ratansairohith
Are you able to install it on rpi 4?

@Ratansairohith
Copy link

@ling9601 Nope i was unable to install it on rpi 4. If you find a way please let me know.

@Co2Link
Copy link

Co2Link commented Feb 17, 2021

yes, I am not at home now. I will share the installation tomorrow

@Co2Link
Copy link

Co2Link commented Feb 18, 2021

@Ratansairohith
The installation was tested on RP4b with the latest RP OS.

Try the following step to build the wheel and install it.

  1. install dependency for compile
sudo apt-get install cmake libprotobuf-dev protobuf-compiler
  1. 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
  1. compile preparation
cd /path/to/MNN
./schema/generate.sh
mkdir pymnn_build
  1. 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
  1. 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
  1. Install wheel
pip install pymnn/pip_package/dist/MNN-1.1.3-cp37-cp37m-manylinux2014_armv7l.whl
  1. 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

@Ratansairohith
Copy link

@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.

@fly-studio
Copy link

fly-studio commented May 25, 2021

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

@mosheliv
Copy link

I wonder if you can share the speed you get on the rpi with MNN? FPS for the models you use?

@GuoJingtao-1997
Copy link

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')
...

@wangzhaode
Copy link
Collaborator

@Ratansairohith The installation was tested on RP4b with the latest RP OS.

Try the following step to build the wheel and install it.

  1. install dependency for compile
sudo apt-get install cmake libprotobuf-dev protobuf-compiler
  1. 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
  1. compile preparation
cd /path/to/MNN
./schema/generate.sh
mkdir pymnn_build
  1. 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
  1. 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
  1. Install wheel
pip install pymnn/pip_package/dist/MNN-1.1.3-cp37-cp37m-manylinux2014_armv7l.whl
  1. 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.

@mosheliv
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants