Constructing deep learning application with raspberry pie 4B (5) tersorflow

Time:2020-10-18

preface

Last time we installed the environment for Python. In this article, we set up a development environment for tensorflow and keras.

Constructing deep learning application with raspberry pie 4B (5) tersorflow

It has to be said that, compared with Python, tensorflow supports various systems really well. There are corresponding pre compiled installation packages for all platforms and versions, and the official documents are also very detailed (but it does not mean that there are no holes, see below). It is a good choice for engineering.

The Python code is more python, so many of the latest models and algorithms are released by python. In the long run, the two will learn from each other and catch up with each other in a benign competition state. For developers, they should know something about it.

Now the mature version of raspberry pie tensorflow is 1.14.0, and the latest version is 2.3.0. There are still more mainstream applications in 1. X series, but 2. X integration keras is obviously better for use, especially in model transformation, which is also oriented to the future, so here we use virtual environment to deploy both.

Installing tensorflow 1.14

1. Build the virtual environment of tensorflow 1.14

python3 -m venv --system-site-packages ~/my_envs/tensorflow
source ~/my_envs/tensorflow/bin/activate

Tip:

The parameter system site packages is used to reference the installed basic packages of the system, so as to facilitate the sharing of some basic libraries. You can create a new no global site in the virtual environment lib / python3.7 directory- packages.txt File to switch the reference state.

2. Download the WHL installation package

Download the compiled version of the WHL package:

wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.14.0-buster/tensorflow-1.14.0-cp37-none-linux_armv7l.whl
wget https://github.com/lhelontra/tensorflow-on-arm/releases/download/v2.3.0/tensorflow-2.3.0-cp37-none-linux_armv7l.whl

3. Install tensorflow 1.14.0

pip install tensorflow-1.14.0-cp37-none-linux_armv7l.whl 
#Test installation
python
>>> import tensorflow as tf
>>> print(tf.reduce_sum(tf.random.normal([1000, 1000])))
>>> tf.__version__

Constructing deep learning application with raspberry pie 4B (5) tersorflow

Tip:

Here is a tutorial on the official website(https://www.tensorflow.org/in…)PIP install tensorflow is recommended. Hadoop file system load error will be encountered libhdfs.so Error in: cannot open shared object file: no such file or directory.

This is mainly caused by the fact that the Hadoop file system is not installed in raspberry pie. We can not use it here for the time being, so it can be repaired by lazy loading. There are still problems with version 1.14.0 in the official PIP library, so the open source version on GitHub is recommended.

Constructing deep learning application with raspberry pie 4B (5) tersorflow

4. Install keras 2.2.5

The keras matching tensorflow 1.14.0 is version 2.2.5

pip install keras==2.2.5

Constructing deep learning application with raspberry pie 4B (5) tersorflow

Tip:

Tensorflow and keras have strict version correspondence. For more versions, please refer to the table on this website.https://docs.floydhub.com/gui…

Installing tensorflow 2.3

1. Build the virtual environment of tensorflow 2.3.0

#Exit virtual environment
deactivate
python3 -m venv --system-site-packages ~/my_envs/tf2
source ~/my_envs/tf2/bin/activate

2. Installing tensorflow 2.3.0

pip install tensorflow-2.3.0-cp37-none-linux_armv7l.whl
#Test installation
python
>>> import tensorflow as tf
>>> print(tf.reduce_sum(tf.random.normal([1000, 1000])))
>>> tf.__version__

Constructing deep learning application with raspberry pie 4B (5) tersorflow

3. Install keras 2.4.3

pip install keras==2.4.3

Constructing deep learning application with raspberry pie 4B (5) tersorflow

Installation package download

Constructing deep learning application with raspberry pie 4B (5) tersorflow

The relevant documents and information can be answered in the background of official account: rpi05, get the download link.

Next Preview

We will install tensorflow Lite,
And do image classification and target detection tasks,
Coming soon…

Constructing deep learning application with raspberry pie 4B (5) tersorflow