Install Tensorflow and Keras on the Raspberry Pi

· 3 min read
Install Tensorflow and Keras on the Raspberry Pi

Tensorflow is a library for high-scale numerical computing and Machine Learning. Google created Tensorflow and opened to the public with an open source license. Tensorflow can be used for train models and running deep learning with a neural network. It's like the nerves of humans who can learn objects quickly and deeply.

Tensorflow can be used to object recognition, natural language processing recurrent neural networks, handwriting recognition, and others. This is Tensorflow, a library for deep learning using artificial neural networks. It will work and study objects just as humans learn.

To learn more about Tensorflow, please visit the https://www.tensorflow.org/ page.

Same with Keras. Keras is a library that is built with python to build and train deep learning. Keras can be used for research, prototype, or production. To learn Keras, please visit the official website at https://keras.io/.

In this article, we will try Tensorflow and Keras installations on a Raspberry Pi device.

Preparation

You must have a Raspberry Pi 3 Model B+ (Buy Here) that has OpenCV installed. Please read the previous article entitled Install OpenCV 4 on the Raspberry Pi. Suggested SSH or VNC access has been installed before.

In this tutorial, we will install using the cv Virtual Environment that was previously created.

Installation

For Tensorflow and Keras, the Raspberry Pi currently provides a wheel for python. You can directly install via PIP. However, when we tried, we got some errors. It might be fixed soon in another version. We will still write the method, but we will write how to install different versions.

Install in Easily way

Before installing tensorflow and Keras, install some of the libraries that are needed.

sudo apt-get install python3-numpy
sudo apt-get install libblas-dev
sudo apt-get install liblapack-dev
sudo apt-get install python3-dev 
sudo apt-get install libatlas-base-dev
sudo apt-get install gfortran
sudo apt-get install python3-setuptools
sudo apt-get install python3-scipy
sudo apt-get update
sudo apt-get install python3-h5py

When done, go to Virtual Environment cv, and install it with PIP.

workon cv
pip install --upgrade scipy
pip install --upgrade cython
pip install tensorflow
pip install keras 

If there is no error, then you can successfully install Tensorflow and Keras in an easy way. You can go directly to the installation Test section. However, if you don't succeed, try the installation in another way below.

Install in other ways

Before continuing, make sure the install dependencies needed in the easy way above are already running. When this article was written, the latest version of tensorflow is v1.13.1. You can try checking and installing the latest version on the page https://github.com/lhelontra/tensorflow-on-arm/releases.

workon cv
wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.13.1/tensorflow-1.13.1-cp35-none-linux_armv7l.whl
pip install tensorflow-1.13.1-cp35-none-linux_armv7l.whl
pip install tensorflow

To install it Keras, we get an error when installing Scipy. Therefore, we try to install the manual for the Scipy.

wget https://www.piwheels.org/simple/scipy/scipy-1.2.1-cp35-cp35m-linux_armv7l.whl
pip install scipy-1.2.1-cp35-cp35m-linux_armv7l.whl
pip install scipy

Then install Keras.

pip install keras

If it's ok, you can test the installation.

Installation Test

Type the following command to test the Tensorflow and Keras installation.

Tensorflow

python -c 'import tensorflow as tf; print(tf.__version__)'

If the output is a version, for example, 1.13.1, then your tensorflow installation process is successful.

Keras

python -c 'import keras; print(keras.__version__)'

If the output is a version like 2.2.4, that means your Keras install is successful.

Kesimpulan

Tensorflow and Keras are essential libraries for those of you who are studying deep learning and neural networks. Also, the good thing is, Tensorflow and Keras can be installed on Raspberry Pi quickly. This will make our Raspberry Pi even smarter. The development can be even wider.

Follow Teknotut to learn about other Computer Vision.