Theano with Keras on Raspberry Pi
Asked Answered
A

3

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

Acquittance answered 29/10, 2016 at 8:8 Comment(8)
Have you tried training simple models in TF/Theano alone? At least this can narrow down problem cause.Mcgehee
Can you try with a debug version of tensorflow? bazel build -c dbg to build it.Blandish
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?Knotting
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.Acquittance
Is there an answer to this question?Legra
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.Acquittance
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.We
since you have it working with Tensorflow, have you tried switching the backend environment variable by doing KERAS_BACKEND=theano python yourmodel.py?Foucault
B
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.

Bosson answered 11/1, 2019 at 12:30 Comment(0)
G
-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.

Grahamgrahame answered 10/3, 2019 at 4:57 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker.Castilian
H
-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.

Hexosan answered 2/1, 2018 at 0:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.