TensorFlow 1.9官网树莓派安装教程

Install TensorFlow on Raspbian

This guide explains how to install TensorFlow on a Raspberry Pi running Raspbian. Although these instructions might also work on other Pi variants, we have only tested (and we only support) these instructions on machines meeting the following requirements:

  • Raspberry Pi devices running Raspbian 9.0 or higher

Determine how to install TensorFlow

You must pick the mechanism by which you install TensorFlow. The supported choices are as follows:

  • "Native" pip.
  • Cross-compiling from sources.

We recommend pip installation.

Installing with native pip

We have uploaded the TensorFlow binaries to piwheels.org. Therefore, you can install TensorFlow through pip.

The REQUIRED_PACKAGES section of setup.py lists the packages that pip will install or upgrade.

Prerequisite: Python

In order to install TensorFlow, your system must contain one of the following Python versions:

  • Python 2.7
  • Python 3.4+

If your system does not already have one of the preceding Python versions, install it now. It should already be included when Raspbian was installed though, so no extra steps should be needed.

Prerequisite: pip

Pip installs and manages software packages written in Python. If you intend to install with native pip, then one of the following flavors of pip must be installed on your system:

  • pip3, for Python 3.n (preferred).
  • pip, for Python 2.7.

pip or pip3 was probably installed on your system when you installed Python. To determine whether pip or pip3 is actually installed on your system, issue one of the following commands:

$ pip3 -V # for Python 3.n
$ pip -V  # for Python 2.7

If it gives the error "Command not found", then the package has not been installed yet. To install if for the first time, run:

$ sudo apt-get install python3-pip # for Python 3.n
sudo apt-get install python-pip # for Python 2.7

You can find more help on installing and upgrading pip in the Raspberry Pi documentation.

Prerequisite: Atlas

Atlas is a linear algebra library that numpy depends on, and so needs to be installed before TensorFlow. To add it to your system, run the following command:

$ sudo apt install libatlas-base-dev

Install TensorFlow

Assuming the prerequisite software is installed on your Pi, install TensorFlow by invoking one of the following commands:

 <pre> $ <b>pip3 install tensorflow</b>     # Python 3.n $ <b>pip install tensorflow</b>      # Python 2.7</pre>

This can take some time on certain platforms like the Pi Zero, where some Python packages like scipy that TensorFlow depends on need to be compiled before the installation can complete. The Python 3 version will typically be faster to install because piwheels.org has pre-built versions of the dependencies available, so this is our recommended option.

Next Steps

After installing TensorFlow, validate your installation to confirm that the installation worked properly.

Uninstalling TensorFlow

To uninstall TensorFlow, issue one of following commands:

$ pip uninstall tensorflow
$ pip3 uninstall tensorflow 

Cross-compiling from sources

Cross-compilation means building on a different machine than than you‘ll be deploying on. Since Raspberry Pi‘s only have limited RAM and comparatively slow processors, and TensorFlow has a large amount of source code to compile, it‘s easier to use a MacOS or Linux desktop or laptop to handle the build process. Because it can take over 24 hours to build on a Pi, and requires external swap space to cope with the memory shortage, we recommend using cross-compilation if you do need to compile TensorFlow from source. To make the dependency management process easier, we also recommend using Docker to help simplify building.

Note that we provide well-tested, pre-built TensorFlow binaries for Raspbian systems. So, don‘t build a TensorFlow binary yourself unless you are very comfortable building complex packages from source and dealing with the inevitable aftermath should things not go exactly as documented

Prerequisite: Docker

Install Docker on your machine as described in the Docker documentation.

Clone the TensorFlow repository

Start the process of building TensorFlow by cloning a TensorFlow repository.

To clone the latest TensorFlow repository, issue the following command:

$ git clone https://github.com/tensorflow/tensorflow 

The preceding git clone command creates a subdirectory named tensorflow. After cloning, you may optionally build a specific branch (such as a release branch) by invoking the following commands:

$ cd tensorflow
$ git checkout Branch # where Branch is the desired branch

For example, to work with the r1.0 release instead of the master release, issue the following command:

$ git checkout r1.0

Build from source

To compile TensorFlow and produce a binary pip can install, do the following:

  1. Start a terminal.
  2. Navigate to the directory containing the tensorflow source code.
  3. Run a command to cross-compile the library, for example:
$ CI_DOCKER_EXTRA_PARAMS="-e CI_BUILD_PYTHON=python3 -e CROSSTOOL_PYTHON_INCLUDE_PATH=/usr/include/python3.4" tensorflow/tools/ci_build/ci_build.sh PI-PYTHON3 tensorflow/tools/ci_build/pi/build_raspberry_pi.sh
 

This will build a pip .whl file for Python 3.4, with Arm v7 instructions that will only work on the Pi models 2 or 3. These NEON instructions are required for the fastest operation on those devices, but you can build a library that will run across all Pi devices by passing PI_ONE at the end of the command line. You can also target Python 2.7 by omitting the initial docker parameters. Here‘s an example of building for Python 2.7 and Raspberry Pi model Zero or One devices:

$ tensorflow/tools/ci_build/ci_build.sh PI tensorflow/tools/ci_build/pi/build_raspberry_pi.sh PI_ONE

This will take some time to complete, typically twenty or thirty minutes, and should produce a .whl file in an output-artifacts sub-folder inside your source tree at the end. This wheel file can be installed through pip or pip3 (depending on your Python version) by copying it to a Raspberry Pi and running a terminal command like this (with the name of your actual file substituted):

$ pip3 install tensorflow-1.9.0-cp34-none-linux_armv7l.whl

Troubleshooting the build

The build script uses Docker internally to create a Linux virtual machine to handle the compilation. If you do have problems running the script, first check that you‘re able to run Docker tests like docker run hello-world on your system.

If you‘re building from the latest development branch, try syncing to an older version that‘s known to work, for example release 1.9, with a command like this:

$ git checkout r1.0

Validate your installation

To validate your TensorFlow installation, do the following:

  1. Ensure that your environment is prepared to run TensorFlow programs.
  2. Run a short TensorFlow program.

Prepare your environment

If you installed on native pip, Virtualenv, or Anaconda, then do the following:

  1. Start a terminal.
  2. If you installed TensorFlow source code, navigate to any directory except one containing TensorFlow source code.

Run a short TensorFlow program

Invoke python from your shell as follows:

$ python

Enter the following short program inside the python interactive shell:

# Pythonimport tensorflow as tfhello = tf.constant(‘Hello, TensorFlow!‘)sess = tf.Session()print(sess.run(hello))

If the system outputs the following, then you are ready to begin writing TensorFlow programs:

Hello, TensorFlow!

If you‘re running with Python 3.5, you may see a warning when you first import TensorFlow. This is not an error, and TensorFlow should continue to run with no problems, despite the log message.

If the system outputs an error message instead of a greeting, see Common installation problems.

To learn more, see the TensorFlow tutorials.

Common installation problems

We are relying on Stack Overflow to document TensorFlow installation problems and their remedies. The following table contains links to Stack Overflow answers for some common installation problems. If you encounter an error message or other installation problem not listed in the following table, search for it on Stack Overflow. If Stack Overflow doesn‘t show the error message, ask a new question about it on Stack Overflow and specify the tensorflow tag.

Stack Overflow Link Error Message
42006320
ImportError: Traceback (most recent call last):
File ".../tensorflow/core/framework/graph_pb2.py", line 6, in
from google.protobuf import descriptor as _descriptor
ImportError: cannot import name ‘descriptor‘
33623453
IOError: [Errno 2] No such file or directory:
  ‘/tmp/pip-o6Tpui-build/setup.py‘
35190574
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify
  failed
42009190
  Installing collected packages: setuptools, protobuf, wheel, numpy, tensorflow
  Found existing installation: setuptools 1.1.6
  Uninstalling setuptools-1.1.6:
  Exception:
  ...
  [Errno 1] Operation not permitted:
  ‘/tmp/pip-a1DXRT-uninstall/.../lib/python/_markerlib‘ 
33622019
ImportError: No module named copyreg
37810228 During a pip install operation, the system returns:

OSError: [Errno 1] Operation not permitted
33622842 An import tensorflow statement triggers an error such as the following:

Traceback (most recent call last):
  File "", line 1, in
  File "/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py",
    line 4, in
    from tensorflow.python import *
    ...
  File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/tensor_shape_pb2.py",
    line 22, in
    serialized_pb=_b(‘\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow\"d\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02
      \x03(\x0b\x32
      .tensorflow.TensorShapeProto.Dim\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01
      \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3‘)
  TypeError: __init__() got an unexpected keyword argument ‘syntax‘

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

原文地址:https://www.cnblogs.com/RM-Anton/p/9417039.html

时间: 2024-11-05 23:26:08

TensorFlow 1.9官网树莓派安装教程的相关文章

翻译BonoboService官网的安装教程

This page covers simple Bonobo Git Server installation. Be sure to check prerequisites page before installation and for other sections visit the documentation page. 此页包括简单的Bonobo Git 服务安装.在安装和查看文档页之前要先查看系统要求页. The following steps covers an installati

mysql安装文档(Linux 官网yum安装版)

mysql安装文档(官网yum安装Linx版) 创建时间:2016-12-20 文档目的 在Linux下安装mysql服务端应用. (注:本文档采用yum库安装方式安装mysql应用,本文假设您的系统中没有安装第三方发布的rpm包,如果您已经安装了第三方rpm包,请参考文中"替换第三方发布mysql"的内容) 系统环境 操作系统:centos 7 (3.10.0-229.el7.x86_64) mysql版本:mysql57-community-release-el7-9.noarch

centos 7 官网下载安装mysql-server

官网下载安装mysql-server # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm # rpm -ivh mysql-community-release-el7-5.noarch.rpm # yum install mysql-community-server 安装成功后重启mysql服务. # service mysqld restart 初次安装mysql,root账户没有密码. [[emai

Kotlin 官网 文档 教程 视频 资源

重要资源 Kotlin 官网(官网源码.英文文档) Kotlin 中文文档 系列教程:Kotlin for android developers(Summary.整理) Kotlin on GitHub (2017.5.28 有14K星星) Kotlin 系列视频教程 掘金kotlin社区 开始用 Kotlin 之前 将 Kotlin 用于生产环境:你在犹豫什么?为什么我要改用 Kotlin?用 Kotlin 开发 Android 项目是一种什么样的感受?用 Kotlin 开发 Android

Locust的官网及安装

Locust官网: https://docs.locust.io/en/latest/installation.html for Python 3: $ python3 -m pip install locustio 我本地已安装python3,windows打开命令行,输入 pip install locustio自动开始安装.时间不短,因为不仅安装locustio,还同时会装requests.flask等依赖库.(第一次安装报错提示xxxx,重新安装了最新python可以正常安装了). 安装

UiPath官网认证中文教程

RPA之家公众号:RPA之家 RPA之家官网:http://rpazj.com 斗鱼直播:http://www.douyu.com/rpazj UiPath中文社区QQ群:465630324 RPA&UiPath高级课程知识点QA:链接: https://pan.baidu.com/s/1G2U0kFS0bs8NwsE376DqJg 提取码: tcc8 获取邮件相关信息:链接: https://pan.baidu.com/s/1IFT1vTEnHZDpKehoPIa7Mg 提取码: htct U

maven官网下载安装步骤

第一大步:下载. a.俗话说:"巧妇难为无米之炊"嘛!我这里用的是 ZIP Archive 版的,win7 64位的机器支持这个,所以我建议都用这个.因为这个简单嘛,而且还干净. 地址见图 拉倒最下面,看清楚了64bit ZIP Archive ,点击Download. 2 b.点开之后会进入另一个页面,但却没有开始下载,这个时候不用怕,看不懂没关系,你只要知道他是要让你们登录(login),或者 申请账号(sign up)个就行了,登录或者申请成功后就会开始下载.(记住密码要字母和数

TensorFlow介绍(官网资料)

关于 TensorFlow TensorFlow? 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库.节点(Nodes)在图中表示数学操作,图中的线(edges)则表示在节点间相互联系的多维数据数组,即张量(tensor).它灵活的架构让你可以在多种平台上展开计算,例如台式计算机中的一个或多个CPU(或GPU),服务器,移动设备等等.TensorFlow 最初由Google大脑小组(隶属于Google机器智能研究机构)的研究员和工程师们开发出来,用于机器学习和深度

MySQL官网下载安装.rpm包

系统环境: Centos 7.6关闭selinux和 防火墙卸载系统初始自带的MariaDB#yum remove -y mariadb*1.浏览器搜索MySQL 2.导航栏点击下载 3.下拉找到社区版 4.下载包含比较全的包 5.下载完成后,上传并解压包 6.安装顺序依次安装1. rpm -ivh mysql-community-common-8.0.17-1.el7.x86_64.rpm2. rpm -ivh mysql-community-libs-8.0.17-1.el7.x86_64.