28

I am trying to get Theano to run with Keras on a Raspberry Pi 3 (B) without success. I tried Ubuntu MATE and Raspbian as operating systems, without success. To install Theano and Keras, I have taken following steps:

  1. Install miniconda (armv7 distribution)
  2. Install all Theano dependencies (as shown here) through Conda (if possible), pip and apt-get
  3. Install Theano
  4. Install Keras

The aforementioned steps work without any issues. In the next step, I built a little test script (test.py) which loads an already built model via

from keras.models import load_model
model = load_model('model.hdf5')

When the model is being loaded, I get the following error

Segmentation fault (core dumped)

Then I tried to investigate the issue further, following this answer on SO (What causes a Python segmentation fault?):

gdb python
> run test.py

When I run this I get:

Program received SIGSEV, Segmentation fault.
0x76fd9822 in ?? () from /lib/ld-linux-armhf.so.3

In the next step I ran in the gdb shell:

> backtrace

and got

#0  0x76fd9822 in ?? () from /lib/ld-linux-armhf.so.3
#1  0x76fd983a in ?? () from /lib/ld-linux-armhf.so.3

this is the point where I don't know any further and I would like to ask, if anyone could point me into a direction on how to fix this issue and get keras + theano to run on a Raspberry Pi.

(I have also tried TensorFlow as an alternative, but getting the same issue)

Thanks a lot.


EDIT

I have done some more investigations. If I run Keras with TensorFlow the problem seems to change a little bit. I ran gdb again, but the error happens now in numpy, especially in libopenblas.so.0

Program received signal SIGSEV, Segmentation fault.
0x75ead7cc in inner_thread()
from /home/<path>/numpy/core/../../../../libopenblas.so.0

Does this help?


EDIT 2

I have installed everything without using Miniconda and Keras works now with TensorFlow (but not with Theano yet).

mrry
  • 125,488
  • 26
  • 399
  • 400
peschn
  • 305
  • 3
  • 8
  • 1
    Have you tried training simple models in TF/Theano alone? At least this can narrow down problem cause. – Kh40tiK Oct 29 '16 at 08:21
  • Can you try with a debug version of tensorflow? `bazel build -c dbg` to build it. – drpng Nov 08 '16 at 02:04
  • Have you had any success by now? I was thinking about running Keras (probably with TF) on a Rasperry PI as well. I have not tried it, I was just gathering information in general. Will it work, by now? – muuh Jul 03 '17 at 09:24
  • 1
    It will work if you don't use Miniconda (or at least I wasn't able to manage to get Miniconda to work with Keras/TF). I think as long as you don't want to develop anything on the Pi but run an application (which was the case for me), not using Miniconda is totally fine. I haven't tried to fix the install with Theano, maybe it works by now. – peschn Jul 04 '17 at 08:00
  • Is there an answer to this question? – Michael Ababio Dec 26 '17 at 14:14
  • Not yet, at least not to the question on how to install keras, theano (tensorflow) and miniconda all together. It may work with the new versions of the different libs (theano, tensorflow, miniconda, keras), but I haven't tried it. Also I don't know, why the errors are shown, as I haven't investigated the issue any further. – peschn Dec 28 '17 at 11:30
  • I would recommend installing Theano or TensorFlow from source. It is possible that there are some compatibility issues between the Pi and the pre-built ARM TensorFlow/Theno binaries. – James Mchugh Mar 08 '19 at 03:04
  • since you have it working with Tensorflow, have you tried switching the backend environment variable by doing `KERAS_BACKEND=theano python yourmodel.py`? – VnC Apr 24 '19 at 15:58

3 Answers3

1

If you had provided the version of python it would have been useful. If you are using python3.7 try reverting back to python3.6 because keras has not yet caught up to the development and there are a lot of problems installing tensorflow with keras on python3.7. I am putting emphasis on version here because I recently faced same problem installing using conda and I realised the issue was python version.

But I also had problems getting tensorflow to work on PI. But I used direct installation using pip from ubuntu and not miniconda and it worked. The way that Google Tensorflow team itself mentions is best is to actually build tensorflow from source by following instructions from this link. https://www.tensorflow.org/install/source_rpi

So try to downgrade the version of python to 3.6 or less if you can and try to install using pip or build from source using python3.6 or 3.7.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
-1

I think running Keras and Tensorflow on Raspberry Pi is not a good idea because running those on my college machine which is comparatively far more powerful than Raspberry Pi, gives a lot of trouble. Maybe the errors are caused because of insufficient memory. I am guessing this because I face this problem in my machine when I try to run some complex models.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker.](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead) – Til Mar 10 '19 at 05:22
-2

For now the solution is to avoid miniconda when installing.

To diagnose further, it would be helpful for ld-linux-armhf.so.3 and libopenblas.so.0 to have -g debug symbols available.

J_H
  • 17,926
  • 4
  • 24
  • 44