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
来源: http://www.jianshu.com/p/7f031fa2739a