Theano with Keras on Raspberry Pi
Question:
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:
- Install miniconda (armv7 distribution)
- Install all Theano dependencies (as shown here) through Conda (if possible),
pip
and apt-get
- Install Theano
- 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).
Answers:
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.
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.
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.
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:
- Install miniconda (armv7 distribution)
- Install all Theano dependencies (as shown here) through Conda (if possible),
pip
andapt-get
- Install Theano
- 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).
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.
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.
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.