apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.78k stars 6.79k forks source link

Fail to run example code with Raspberry Pi #16379

Open diegobernardes opened 5 years ago

diegobernardes commented 5 years ago

Description

With a fresh Raspbian install on a Raspberry Pi 4 I'm not able to run this example. Would be nice to have a pre compiled wheel for Raspberry that includes the OpenCV. I tried to build the MXNet from the source, but I'm having an error as well.

Environment info

----------Python Info----------
Version      : 3.7.3
Compiler     : GCC 8.2.0
Build        : ('default', 'Apr  3 2019 05:39:12')
Arch         : ('32bit', 'ELF')
------------Pip Info-----------
Version      : 18.1
Directory    : /usr/lib/python3/dist-packages/pip
----------MXNet Info-----------
Version      : 1.5.0
Directory    : /home/pi/.local/lib/python3.7/site-packages/mxnet
Commit hash file "/home/pi/.local/lib/python3.7/site-packages/mxnet/COMMIT_HASH" not found. Not installed from pre-built package or built from source.
Library      : ['/home/pi/.local/lib/python3.7/site-packages/mxnet/libmxnet.so']
Build features:
No runtime build feature info available
----------System Info----------
Platform     : Linux-4.19.57-v7l+-armv7l-with-debian-10.0
system       : Linux
node         : raspberrypi
release      : 4.19.57-v7l+
version      : #1244 SMP Thu Jul 4 18:48:07 BST 2019
----------Hardware Info----------
machine      : armv7l
processor    :
Architecture:        armv7l
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  1
Core(s) per socket:  4
Socket(s):           1
Vendor ID:           ARM
Model:               3
Model name:          Cortex-A72
Stepping:            r0p3
CPU max MHz:         1500.0000
CPU min MHz:         600.0000
BogoMIPS:            270.00
Flags:               half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0327 sec, LOAD: 0.5603 sec.
Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.0068 sec, LOAD: 0.2168 sec.
Timing for Gluon Tutorial(cn): https://zh.gluon.ai, DNS: 0.0319 sec, LOAD: 0.6907 sec.
Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0062 sec, LOAD: 0.3093 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.1843 sec, LOAD: 0.5646 sec.
Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0092 sec, LOAD: 0.1116 sec.
----------Environment----------

Error Message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/gluoncv/data/transforms/presets/yolo.py", line 99, in load_test
    imgs = [mx.image.imread(f) for f in filenames]
  File "/home/pi/.local/lib/python3.7/site-packages/gluoncv/data/transforms/presets/yolo.py", line 99, in <listcomp>
    imgs = [mx.image.imread(f) for f in filenames]
  File "/home/pi/.local/lib/python3.7/site-packages/mxnet/image/image.py", line 83, in imread
    return _internal._cvimread(filename, *args, **kwargs)
  File "<string>", line 35, in _cvimread
  File "/home/pi/.local/lib/python3.7/site-packages/mxnet/_ctypes/ndarray.py", line 92, in _imperative_invoke
    ctypes.byref(out_stypes)))
  File "/home/pi/.local/lib/python3.7/site-packages/mxnet/base.py", line 252, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [00:10:34] /work/mxnet/src/io/image_io.cc:249: Build with USE_OPENCV=1 for image io.

Stack trace returned 8 entries:
[bt] (0) /home/pi/.local/lib/python3.7/site-packages/mxnet/libmxnet.so(dmlc::StackTrace()+0x34) [0xadf0aacc]
[bt] (1) /home/pi/.local/lib/python3.7/site-packages/mxnet/libmxnet.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x30) [0xadf0adb0]
[bt] (2) /home/pi/.local/lib/python3.7/site-packages/mxnet/libmxnet.so(mxnet::io::Imread(nnvm::NodeAttrs const&, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray> > const&, std::vector<mxnet::NDArray, std::allocator<mxnet::NDArray> >*)+0x3c) [0xae059d38]
[bt] (3) /home/pi/.local/lib/python3.7/site-packages/mxnet/libmxnet.so(mxnet::Imperative::Invoke(mxnet::Context const&, nnvm::NodeAttrs const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&)+0x1b4) [0xae0389a0]
[bt] (4) /home/pi/.local/lib/python3.7/site-packages/mxnet/libmxnet.so(MXImperativeInvokeImpl(void*, int, void**, int*, void***, int, char const**, char const**)+0x3b4) [0xadf31314]
[bt] (5) /home/pi/.local/lib/python3.7/site-packages/mxnet/libmxnet.so(MXImperativeInvokeEx+0x80) [0xadf32240]
[bt] (6) /usr/lib/arm-linux-gnueabihf/libffi.so.6(ffi_call_VFP+0x54) [0xb64d8cc0]
[bt] (7) /usr/lib/arm-linux-gnueabihf/libffi.so.6(ffi_call+0x154) [0xb64d96cc]

Minimum reproducible example

I've followed this installation guide.

image

Steps to reproduce

  1. Execute this example.

What have you tried to solve it?

  1. Tried to build from source, but without success as well.
mxnet-label-bot commented 5 years ago

Hey, this is the MXNet Label Bot. Thank you for submitting the issue! I will try and suggest some labels so that the appropriate MXNet community members can help resolve it. Here are my recommended label(s): Build

szha commented 5 years ago

Which pip package did you use?

diegobernardes commented 5 years ago

This one. It's on the installation guide on this page.

aGiant commented 4 years ago

This one. It's on the installation guide on this page.

Still error after successfully installed on respberry pi 4b, ubuntu 19.10.1 Python3.6

>>> import mxnet
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/.local/lib/python3.6/site-packages/mxnet/__init__.py", line 24, in <module>
    from .context import Context, current_context, cpu, gpu, cpu_pinned
  File "/home/ubuntu/.local/lib/python3.6/site-packages/mxnet/context.py", line 24, in <module>
    from .base import classproperty, with_metaclass, _MXClassPropertyMetaClass
  File "/home/ubuntu/.local/lib/python3.6/site-packages/mxnet/base.py", line 213, in <module>
    _LIB = _load_lib()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/mxnet/base.py", line 204, in _load_lib
    lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_LOCAL)
  File "/usr/local/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/ubuntu/.local/lib/python3.6/site-packages/mxnet/libmxnet.so: wrong ELF class: ELFCLASS32
pedrooct commented 4 years ago

hi, i'm getting the same error as you on my raspberry pi 3b, until Friday i will compile mxnet and try to create a wheel. I will give my best !

pedrooct commented 4 years ago

hi, i'm getting the same error as you on my raspberry pi 3b, until Friday i will compile mxnet and try to create a wheel. I will give my best !

To compile with no issues for the raspberry pi, at least for what i tested, add to the cmake command this parameters:

- DCMAKE_C_COMPILER=gcc-4.9 -DCMAKE_CXX_COMPILER=g++-4.9.

This will force the use of version 4.9. I tested using the demo.py file and a yolo.py example.

aGiant commented 4 years ago

hi, i'm getting the same error as you on my raspberry pi 3b, until Friday i will compile mxnet and try to create a wheel. I will give my best !

To compile with no issues for the raspberry pi, at least for what i tested, add to the cmake command this parameters:

- DCMAKE_C_COMPILER=gcc-4.9 -DCMAKE_CXX_COMPILER=g++-4.9.

This will force the use of version 4.9. I tested using the demo.py file and a yolo.py example.

Compiling worked, many thanks!

After everything was compiled, just ran python3 setup.py install --user under mxnet/python, then the mxnet lib would be successfully installed.

e0lithic commented 4 years ago

@aGiant or @pedrooct Could you kindly share the reference link for the complete set of instructions for building mxnet on raspberry pi. Thanks

pedrooct commented 4 years ago

@aGiant or @pedrooct Could you kindly share the reference link for the complete set of instructions for building mxnet on raspberry pi. Thanks

HI, i created this tutorial: https://medium.com/@ce4theguys/how-to-compile-mxnet-for-raspberry-pi-fast-7e397c7c8a36 Be careful, the new version of mxnet is broken on compile, use version 1.5.1

Hope this helps!

EDIT: they appear to have fixed 1.6.0 compile errors: https://mxnet.apache.org/get_started?platform=devices&iot=raspberry-pi&

e0lithic commented 4 years ago

@pedrooct Thanks for the medium article, it helped a lot. I tried building mxnet on rpi itself and unfortunately it seems that the device seems to get hanged in the process and everything gets stuck. However , the process you mentioned for emulating worked perfectly. Can the build on the emulated distro be transferred to rpi directly and used as is ? Thanks

pedrooct commented 4 years ago

@pedrooct Thanks for the medium article, it helped a lot. I tried building mxnet on rpi itself and unfortunately it seems that the device seems to get hanged in the process and everything gets stuck. However , the process you mentioned for emulating worked perfectly. Can the build on the emulated distro be transferred to rpi directly and used as is ? Thanks

Hi ! i'm glad it helped you. Responding to the first statement, to compile it on the rpi(1/2gb) you need to increase swap memory to 2 or 3 gb. Responding to the question, when you finish the process of building the libmxnet.so you can just copy the mxnet folder to the raspberry pi and install it with pip as in the tutorial.

Hope this helps you further.

e0lithic commented 4 years ago

@pedrooct Thanks for the detailed instructions it worked out like a charm.

I had one additional query regarding compiling mxnet with NNPACK. According to the instructions at here, we need to make updates to the config.make file. However since you have used the cmake based flow, is there an equivalent version for compiling with NNPACK utilizing cmake instead.

pedrooct commented 4 years ago

@pedrooct Thanks for the detailed instructions it worked out like a charm.

I had one additional query regarding compiling mxnet with NNPACK. According to the instructions at here, we need to make updates to the config.make file. However since you have used the cmake based flow, is there an equivalent version for compiling with NNPACK utilizing cmake instead.

Sorry for the late response. I never tested NNPACK but it is something i will look into. I think rpi 3 1gb is armv6 so probably won't work, rpi4 probably will work but try it and report it :) !