Use Tensorflow on Raspberry Pi
This article describes how to install tensorflow on the Raspberry Pi and how to run the tensorflow model on the Raspberry Pi.
This article applies to Raspberry Pi 3B, 4B
Tensorflow environment installation
1. pip replaces domestic sources. If the
download speed of foreign sources is too slow, it is easy to time out and make mistakes.
Tsinghuayuan
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Doubanyuan
pip config set global.index-url http://pypi.douban.com/simple/
Aliyuan
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
University of Science and Technology of China
pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/
Baidu source
pip config set global.index-url https://mirror.baidu.com/pypi/simple/
Note: The default download timeout time can be changed
pip --default-timeout=600 install **
2. Install tensorflow
Download link: https://github.com/lhelontra/tensorflow-on-arm/releases
Choose a suitable version to download.
This article uses tensorflow-2.0.0-cp37-none-linux_armv7l.whl to
download and upload it to the Raspberry Pi .
pip install tensorflow-2.0.0-cp37-none-linux_armv7l.whl
There may be many timed out during the installation process. You can download the corresponding package first, and then drag it to the Raspberry Pi to install.
Note:
Encountered problems:
solutions:
pip3 install wrapt --ignore-installed
Raspberry Pi runs Tensorflow model
After repeated attempts, I found a way to run the model on the Raspberry Pi
1. Save the model
model.save_weights('model/path_to_saved_model/test.ckpt')
2. Model reading
model = creat_model()
model_to_be_restored.load_weights("model/path_to_saved_model/test.ckpt")