树莓派上使用Tensorflow
本文介绍如何在树莓派上安装tensorflow,介绍如何在树莓派上运行tensorflow模型。
本文适用于树莓派3B、4B
Tensorflow环境安装
1.pip更换国内源
国外源下载速度太慢容易超时出错。
清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/
阿里源
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
中科大源
pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/
百度源
pip config set global.index-url https://mirror.baidu.com/pypi/simple/
注:可以改变默认下载超时时间
pip --default-timeout=600 install **
2.安装tensorflow
下载链接:https://github.com/lhelontra/tensorflow-on-arm/releases
选择一个适合的版本下载。
本文使用tensorflow-2.0.0-cp37-none-linux_armv7l.whl
下载完毕传到树莓派上。
pip install tensorflow-2.0.0-cp37-none-linux_armv7l.whl
安装过程中可能有很多timed out可以先下载对应的包,然后拖到树莓派上安装。
注:
遇到问题:
解决方法:
pip3 install wrapt --ignore-installed
树莓派运行Tensorflow模型
经过不断尝试,找到一种可以在树莓派上运行模型的方法
1.模型保存
model.save_weights('model/path_to_saved_model/test.ckpt')
2.模型读取
model = creat_model()
model_to_be_restored.load_weights("model/path_to_saved_model/test.ckpt")