In this blog post we will be looking at how we can install Keras, an open source neural network library written in Python, on the Raspberry Pi 3. We will be using Theano instead of TensorFlow for our back end because installing TensorFlow on the Raspberry Pi is a tedious task and can cause errors and frustration if not done properly. So let’s start.
First lets install Numpy.
sudo apt-get install python3-numpy
sudo apt-get install libblas-dev sudo apt-get install liblapack-dev sudo apt-get install python3-dev # Possibly already installed sudo apt-get install libatlas-base-dev # Optional sudo apt-get install gfortran sudo apt-get install python3-setuptools # Possibly already installed sudo apt-get install python3-scipy
NOTE: The installation of Scipy takes a few hours (it took me almost 3 hours)
sudo pip3 install scikit-learn sudo pip3 install pillow sudo apt-get install python3-h5py sudo pip3 install --upgrade --no-deps git+git://github.com/Theano/Theano.git
And finally Keras.
sudo pip3 install keras
Now type the following.
sudo pip3 install --upgrade six cd .keras nano keras.json
Insert the following line into the JSON file.
"image_dim_ordering": "th" "backend": "theano"
Save and close the file. Now open a python terminal and import Keras. If your installation was successful no errors should occur. Do note that it is usual to see deprecation warnings while you are installing the packages so don’t be afraid and think that it is not going to work.