美文网首页OpenCv
树莓派安装TensorFlow

树莓派安装TensorFlow

作者: 高巨龙 | 来源:发表于2018-08-24 14:24 被阅读11次

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](https://img.haomeiwen.com/i6540285/67b9ce3d4d908890.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
  • 安装 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

相关文章

网友评论

    本文标题:树莓派安装TensorFlow

    本文链接:https://www.haomeiwen.com/subject/yioviftx.html