作者:江西理工大学-交通091班-李吉平 | 来源:互联网 | 2023-05-23 15:24
InstallingTensorFlowonRaspberryPi3详情在20188月之前在Raspberry安装一个TensorFlow是多么的痛苦!现在Google从Tenso
Installing TensorFlow on Raspberry Pi 3
详情
在2018-8月之前在Raspberry安装一个TensorFlow是多么的痛苦!现在Google从TensorFlow 1.9开始支持树莓派,安装非常方便,只要要两条命令即可以安装成功!
环境是 Python3.5 + TensorFlow1.9 ,其余Python版本可能会安装失败,安装前请检查一下Python版本!如何切换Python版本请查看前面章节!
安装
TensorFlow:1.9
Python环境:3.5.3
硬件: Raspberry 3B
本文升级日期: 2018-8-24
切换Python版本
官方推荐3.4+以上就可,假如环境是3.4以上直接跳到安装TensorFlow步骤!假如Python不是,请先下载Python3.4+后,建立新的Python软连接!这里以3.5.3为例!
查看Python版本
pi@raspberrypi:~ $ python Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit()
假如没有Python3.5,先下载Python3.5
sudo apt-get install python3.5
首先我们删除Python的链接
sudo rm /usr/bin/python
新建一个Python3的链接
sudo ln -s /usr/bin/python3.5 /usr/bin/python
安装TensorFlow
sudo apt-get install libatlas-base-dev 安装过程遇到 Do you want to continue? [Y/n] 输入:Y
image.png
安装 libatlas-base-dev 成功图:
image.png
安装 TensorFlow
sudo pip3 install tensorflow
下载TensorFlow过程:
image.png安装TensorFlow后,会自动下载安装依赖的工具,如:numpy,tensorboard,markdown 等等
image.png一律安装完成后打印信息
Successfully installed absl-py-0.4.0astor-0.7.1gast-0.2.0 grpcio-1.14.1 markdown-2.6.11 numpy-1.15.1 protobuf-3.6.1 tensorboard-1.9.0 tensorflow-1.9.0 termcolor-1.1.0
image.png
测试能否安装成功
安装成功后即可以运行Python3, 可以在任何你想用的平台上使用TensorFlow,下面我们通过一个例子来验证能否可以成功运行TensorFlow。
Python程序
pi@raspberrypi:~ $ python Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf /usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.4 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5 return f(*args, **kwds) /usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412 return f(*args, **kwds) >>> import tensorflow as tf >>> hello = tf.constant('Hello TensorFlow') >>> sess = tf.Session() >>> print(sess.run(hello)) b'Hello TensorFlow' >>>
导入TensorFlow包是会出现警告,可以先忽略它!
image.png
注意:
假如安装出错,更新你的pip版本,执行下面语句:
sudo python -m pip install --upgrade pip