tensorflow 官网安装

来源:互联网 发布:武装突袭3低配置优化 编辑:程序博客网 时间:2024/06/08 03:13

You can install TensorFlow either from our provided binary packages or from thegithub source.

Requirements

The TensorFlow Python API supports Python 2.7 and Python 3.3+.

The GPU version works best with Cuda Toolkit 8.0 andcuDNN v5. Other versions are supported (Cuda toolkit >= 7.0 andcuDNN >= v3) only when installing from sources.Please seeCuda installation fordetails. For Mac OS X, please see Setup GPU forMac.

Overview

We support different ways to install TensorFlow:

  • Pip install: Install TensorFlow on your machine, possibly upgrading previously installed Python packages. May impact existing Python programs on your machine.
  • Virtualenv install: Install TensorFlow in its own directory, not impacting any existing Python programs on your machine.
  • Anaconda install: Install TensorFlow in its own environment for those running the Anaconda Python distribution. Does not impact existing Python programs on your machine.
  • Docker install: Run TensorFlow in a Docker container isolated from all other programs on your machine.
  • Installing from sources: Install TensorFlow by building a pip wheel that you then install using pip.

If you are familiar with Pip, Virtualenv, Anaconda, or Docker, please feel freeto adapt the instructions to your particular needs. The names of the pip andDocker images are listed in the corresponding installation sections.

If you encounter installation errors, seecommon problems for some solutions.

Pip Installation

Pip is a packagemanagement system used to install and manage software packages written inPython.

The packages that will be installed or upgraded during the pip install arelisted in theREQUIRED_PACKAGES section ofsetup.py.

Install pip (or pip3 for python3) if it is not already installed:

# Ubuntu/Linux 64-bit$ sudo apt-get install python-pip python-dev# Mac OS X$ sudo easy_install pip$ sudo easy_install --upgrade six

Then, select the correct binary to install:

# Ubuntu/Linux 64-bit, CPU only, Python 2.7$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl# Mac OS X, CPU only, Python 2.7:$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py2-none-any.whl# Mac OS X, GPU enabled, Python 2.7:$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.11.0-py2-none-any.whl# Ubuntu/Linux 64-bit, CPU only, Python 3.4$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp34-cp34m-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp34-cp34m-linux_x86_64.whl# Ubuntu/Linux 64-bit, CPU only, Python 3.5$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp35-cp35m-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 3.5# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp35-cp35m-linux_x86_64.whl# Mac OS X, CPU only, Python 3.4 or 3.5:$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py3-none-any.whl# Mac OS X, GPU enabled, Python 3.4 or 3.5:$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.11.0-py3-none-any.whl

Install TensorFlow:

# Python 2$ sudo pip install --upgrade $TF_BINARY_URL# Python 3$ sudo pip3 install --upgrade $TF_BINARY_URL

NOTE: If you are upgrading from a previous installation of TensorFlow < 0.7.1,you should uninstall the previous TensorFlowand protobuf using pipuninstall first to make sure you get a clean installation of the updatedprotobuf dependency.

You can now test your installation.

Virtualenv installation

Virtualenv is a toolto keep the dependencies required by different Python projects in separateplaces. The Virtualenv installation of TensorFlow will not overridepre-existing version of the Python packages needed by TensorFlow.

With Virtualenv the installation isas follows:

  • Install pip and Virtualenv.
  • Create a Virtualenv environment.
  • Activate the Virtualenv environment and install TensorFlow in it.
  • After the install you will activate the Virtualenv environment each time you want to use TensorFlow.

Install pip and Virtualenv:

# Ubuntu/Linux 64-bit$ sudo apt-get install python-pip python-dev python-virtualenv# Mac OS X$ sudo easy_install pip$ sudo pip install --upgrade virtualenv

Create a Virtualenv environment in the directory ~/tensorflow:

$ virtualenv --system-site-packages ~/tensorflow

Activate the environment:

$ source ~/tensorflow/bin/activate  # If using bash$ source ~/tensorflow/bin/activate.csh  # If using csh(tensorflow)$  # Your prompt should change

Now, install TensorFlow just as you would for a regular Pip installation. First select the correct binary to install:

# Ubuntu/Linux 64-bit, CPU only, Python 2.7(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl# Mac OS X, CPU only, Python 2.7:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py2-none-any.whl# Mac OS X, GPU enabled, Python 2.7:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.11.0-py2-none-any.whl# Ubuntu/Linux 64-bit, CPU only, Python 3.4(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp34-cp34m-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp34-cp34m-linux_x86_64.whl# Ubuntu/Linux 64-bit, CPU only, Python 3.5(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp35-cp35m-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 3.5# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp35-cp35m-linux_x86_64.whl# Mac OS X, CPU only, Python 3.4 or 3.5:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py3-none-any.whl# Mac OS X, GPU enabled, Python 3.4 or 3.5:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.11.0-py3-none-any.whl

Finally install TensorFlow:

# Python 2(tensorflow)$ pip install --upgrade $TF_BINARY_URL# Python 3(tensorflow)$ pip3 install --upgrade $TF_BINARY_URL

With the Virtualenv environment activated, you can nowtest your installation.

When you are done using TensorFlow, deactivate the environment.

(tensorflow)$ deactivate$  # Your prompt should change back

To use TensorFlow later you will have to activate the Virtualenv environmentagain:

$ source ~/tensorflow/bin/activate  # If using bash.$ source ~/tensorflow/bin/activate.csh  # If using csh.(tensorflow)$  # Your prompt should change.# Run Python programs that use TensorFlow....# When you are done using TensorFlow, deactivate the environment.(tensorflow)$ deactivate

Anaconda installation

Anaconda is a Python distribution thatincludes a large number of standard numeric and scientific computing packages.Anaconda uses a package manager called"conda" thathas its own environment systemsimilar to Virtualenv.

As with Virtualenv, conda environments keep the dependencies required bydifferent Python projects in separate places. The Anaconda environmentinstallation of TensorFlow will not override pre-existing version of the Pythonpackages needed by TensorFlow.

  • Install Anaconda.
  • Create a conda environment.
  • Activate the conda environment and install TensorFlow in it.
  • After the install you will activate the conda environment each time you want to use TensorFlow.
  • Optionally install ipython and other packages into the conda environment

Install Anaconda:

Follow the instructions on the Anaconda downloadsite.

Create a conda environment called tensorflow:

# Python 2.7$ conda create -n tensorflow python=2.7# Python 3.4$ conda create -n tensorflow python=3.4# Python 3.5$ conda create -n tensorflow python=3.5

Activate the environment and use conda or pip to install TensorFlow inside it.

Using conda

A community maintained conda package is available fromconda-forge.

Only the CPU version of TensorFlow is available at the moment and can beinstalled in the conda environment for Python 2 or Python 3.

$ source activate tensorflow(tensorflow)$  # Your prompt should change# Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:(tensorflow)$ conda install -c conda-forge tensorflow

Using pip

If using pip make sure to use the --ignore-installed flag to prevent errorsabouteasy_install.

$ source activate tensorflow(tensorflow)$  # Your prompt should change

Now, install TensorFlow just as you would for a regular Pip installation. Firstselect the correct binary to install:

# Ubuntu/Linux 64-bit, CPU only, Python 2.7(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl# Mac OS X, CPU only, Python 2.7:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py2-none-any.whl# Mac OS X, GPU enabled, Python 2.7:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.11.0-py2-none-any.whl# Ubuntu/Linux 64-bit, CPU only, Python 3.4(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp34-cp34m-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp34-cp34m-linux_x86_64.whl# Ubuntu/Linux 64-bit, CPU only, Python 3.5(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp35-cp35m-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 3.5# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Install from sources" below.(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp35-cp35m-linux_x86_64.whl# Mac OS X, CPU only, Python 3.4 or 3.5:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py3-none-any.whl# Mac OS X, GPU enabled, Python 3.4 or 3.5:(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.11.0-py3-none-any.whl

Finally install TensorFlow:

# Python 2(tensorflow)$ pip install --ignore-installed --upgrade $TF_BINARY_URL# Python 3(tensorflow)$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL

Usage

With the conda environment activated, you can nowtest your installation.

When you are done using TensorFlow, deactivate the environment.

(tensorflow)$ source deactivate$  # Your prompt should change back

To use TensorFlow later you will have to activate the conda environment again:

$ source activate tensorflow(tensorflow)$  # Your prompt should change.# Run Python programs that use TensorFlow....# When you are done using TensorFlow, deactivate the environment.(tensorflow)$ source deactivate

Install IPython

To use tensorflow with IPython it may be necessary to install IPython into thetensorflow environment:

$ source activate tensorflow(tensorflow)$ conda install ipython

Similarly, other Python packages like pandas may need to get installed into thetensorflow environment before they can be used together with tensorflow.

Docker installation

Docker is a system to build self contained versions of aLinux operating system running on your machine. When you install and runTensorFlow via Docker it completely isolates the installation from pre-existingpackages on your machine.

We provide 4 Docker images:

  • gcr.io/tensorflow/tensorflow: TensorFlow CPU binary image.
  • gcr.io/tensorflow/tensorflow:latest-devel: CPU Binary image plus sourcecode.
  • gcr.io/tensorflow/tensorflow:latest-gpu: TensorFlow GPU binary image.
  • gcr.io/tensorflow/tensorflow:latest-devel-gpu: GPU Binary image plus sourcecode.

We also have tags with latest replaced by a released version (e.g.,0.11.0-gpu).

With Docker the installation is as follows:

  • Install Docker on your machine.
  • Create a Dockergroupto allow launching containers without sudo.
  • Launch a Docker container with the TensorFlow image. The image gets downloaded automatically on first launch.

See installing Docker forinstructions on installing Docker on your machine.

After Docker is installed, launch a Docker container with the TensorFlow binaryimage as follows.

$ docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow

The option -p 8888:8888 is used to publish the Docker container᾿s internalport to the host machine, in this case to ensure Jupyter notebook connection.

The format of the port mapping is hostPort:containerPort. You can specify anyvalid port number for the host port but have to use8888 for the containerport portion.

If you're using a container with GPU support, some additional flags must bepassed to expose the GPU device to the container.

For NVidia GPU support install latest NVidia drivers andnvidia-docker. Run with

$ nvidia-docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow:latest-gpu

If you have a problem running nvidia-docker, then using the default config, weinclude ascriptin the repo with these flags, so the command-line would look like

$ path/to/repo/tensorflow/tools/docker/docker_run_gpu.sh -p 8888:8888 gcr.io/tensorflow/tensorflow:latest-gpu

For more details see TensorFlow dockerreadme.

You can now test your installation withinthe Docker container.

Test the TensorFlow installation

(Optional, Linux) Enable GPU Support

If you installed the GPU version of TensorFlow, you must also install the CudaToolkit 8.0 and cuDNN v5. Please seeCudainstallation.

You also need to set the LD_LIBRARY_PATH and CUDA_HOME environmentvariables. Consider adding the commands below to your~/.bash_profile. Theseassume your CUDA installation is in /usr/local/cuda:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"export CUDA_HOME=/usr/local/cuda

Run TensorFlow from the Command Line

See common problems if an error happens.

Open a terminal and type the following:

$ python...>>> import tensorflow as tf>>> hello = tf.constant('Hello, TensorFlow!')>>> sess = tf.Session()>>> print(sess.run(hello))Hello, TensorFlow!>>> a = tf.constant(10)>>> b = tf.constant(32)>>> print(sess.run(a + b))42>>>

Run a TensorFlow demo model

All TensorFlow packages, including the demo models, are installed in the Pythonlibrary. The exact location of the Python library depends on your system, butis usually one of:

/usr/local/lib/python2.7/dist-packages/tensorflow/usr/local/lib/python2.7/site-packages/tensorflow

You can find out the directory with the following command (make sure to use thePython you installed TensorFlow to, for example, usepython3 instead ofpython if you installed for Python 3):

$ python -c 'import os; import inspect; import tensorflow; print(os.path.dirname(inspect.getfile(tensorflow)))'

The simple demo model for classifying handwritten digits from the MNIST datasetis in the sub-directorymodels/image/mnist/convolutional.py. You can run itfrom the command line as follows (make sure to use the Python you installedTensorFlow with):

# Using 'python -m' to find the program in the python search path:$ python -m tensorflow.models.image.mnist.convolutionalExtracting data/train-images-idx3-ubyte.gzExtracting data/train-labels-idx1-ubyte.gzExtracting data/t10k-images-idx3-ubyte.gzExtracting data/t10k-labels-idx1-ubyte.gz...etc...# You can alternatively pass the path to the model program file to the python# interpreter (make sure to use the python distribution you installed# TensorFlow to, for example, .../python3.X/... for Python 3).$ python /usr/local/lib/python2.7/dist-packages/tensorflow/models/image/mnist/convolutional.py...

Installing from sources

When installing from source you will build a pip wheel that you then installusing pip. You'll need pip for that, so install it as describedabove.

Clone the TensorFlow repository

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

Note that these instructions will install the latest master branch oftensorflow. If you want to install a specific branch (such as a release branch),pass-b <branchname> to the git clone command and --recurse-submodules forr0.8 and earlier to fetch the protobuf library that TensorFlow depends on.

Prepare environment for Linux

Install Bazel

Follow instructions here to install thedependencies for bazel. Then download the latest stable bazel version using theinstaller for your system andrun the installer as mentioned there:

$ chmod +x PATH_TO_INSTALL.SH$ ./PATH_TO_INSTALL.SH --user

Remember to replace PATH_TO_INSTALL.SH with the location where youdownloaded the installer.

Finally, follow the instructions in that script to place bazel into yourbinary path.

Install other dependencies

# For Python 2.7:$ sudo apt-get install python-numpy swig python-dev python-wheel# For Python 3.x:$ sudo apt-get install python3-numpy swig python3-dev python3-wheel

Optional: Install CUDA (GPUs on Linux)

In order to build or run TensorFlow with GPU support, both NVIDIA's Cuda Toolkit(>= 7.0) and cuDNN (>= v3) need to be installed.

TensorFlow GPU support requires having a GPU card with NVidia Compute Capability

= 3.0. Supported cards include but are not limited to:

  • NVidia Titan
  • NVidia Titan X
  • NVidia K20
  • NVidia K40
Check NVIDIA Compute Capability of your GPU card

https://developer.nvidia.com/cuda-gpus

Download and install Cuda Toolkit

https://developer.nvidia.com/cuda-downloads

Install version 8.0 if using our binary releases.

Install the toolkit into e.g. /usr/local/cuda

Download and install cuDNN

https://developer.nvidia.com/cudnn

Download cuDNN v5.

Uncompress and copy the cuDNN files into the toolkit directory. Assuming thetoolkit is installed in/usr/local/cuda, run the following commands (editedto reflect the cuDNN version you downloaded):

tar xvzf cudnn-8.0-linux-x64-v5.1-ga.tgzsudo cp cuda/include/cudnn.h /usr/local/cuda/includesudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Prepare environment for Mac OS X

We recommend using homebrew to install the bazel and SWIGdependencies, and installing python dependencies using easy_install or pip.

Of course you can also install Swig from source without using homebrew. In thatcase, be sure to install its dependencyPCRE and notPCRE2.

Dependencies

Follow instructions here to install thedependencies for bazel. You can then use homebrew to install bazel and SWIG:

$ brew install bazel swig

You can install the python dependencies using easy_install or pip. Usingeasy_install, run

$ sudo easy_install -U six$ sudo easy_install -U numpy$ sudo easy_install wheel

We also recommend the ipython enhanced python shell,which you can install as follows:

$ sudo easy_install ipython

Optional: Setup GPU for Mac

If you plan to build with GPU support you will need to make sure you haveGNU coreutils installed via homebrew:

$ brew install coreutils

Next you will need to make sure you have a recent CUDAToolkit installed by eitherdownloading the package for your version of OSX directly fromNVIDIA or by using theHomebrewCask extension:

$ brew tap caskroom/cask$ brew cask install cuda

Once you have the CUDA Toolkit installed you will need to setup the requiredenvironment variables by adding the following to your~/.bash_profile:

export CUDA_HOME=/usr/local/cudaexport DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$CUDA_HOME/lib"export PATH="$CUDA_HOME/bin:$PATH"

Finally, you will also want to install the CUDA Deep NeuralNetwork (cuDNN v5) library which currentlyrequires an Accelerated Computing DeveloperProgram account.Once you have it downloaded locally, you can unzip and move the header andlibraries to your local CUDA Toolkit folder:

$ sudo mv include/cudnn.h /Developer/NVIDIA/CUDA-8.0/include/$ sudo mv lib/libcudnn* /Developer/NVIDIA/CUDA-8.0/lib$ sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn* /usr/local/cuda/lib/

To verify the CUDA installation, you can build and run deviceQuery to make sureit passes.

$ cp -r /usr/local/cuda/samples ~/cuda-samples$ pushd ~/cuda-samples$ make$ popd$ ~/cuda-samples/bin/x86_64/darwin/release/deviceQuery

If you want to compile tensorflow and have XCode 7.3 and CUDA 7.5 installed, note thatXcode 7.3 is not yet compatible with CUDA 7.5. You can either upgrade to CUDA8.0, or you will need to download Xcode7.2 and select it as your default:

$ sudo xcode-select -s /Application/Xcode-7.2/Xcode.app

Configure the installation

Run the configure script at the root of the tree. The configure scriptasks you for the path to your python interpreter and allows (optional)configuration of the CUDA libraries.

This step is used to locate the python and numpy header files as well asenabling GPU support if you have a CUDA enabled GPU and Toolkit installed.Select the optionY when asked to build TensorFlow with GPU support.

If you have several versions of Cuda or cuDNN installed, you should definitelyselect one explicitly instead of relying on the system default.

For example:

$ ./configurePlease specify the location of python. [Default is /usr/bin/python]:Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] NNo Google Cloud Platform support will be enabled for TensorFlowDo you wish to build TensorFlow with GPU support? [y/N] yGPU support will be enabled for TensorFlowPlease specify which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]:Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:Please specify the cuDNN version you want to use. [Leave empty to use system default]: 5Please specify the location where cuDNN 5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:Please specify a list of comma-separated Cuda compute capabilities you want to build with.You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.Please note that each additional compute capability significantly increases your build time and binary size.[Default is: "3.5,5.2"]: 3.0Setting up Cuda includeSetting up Cuda libSetting up Cuda binSetting up Cuda nvvmSetting up CUPTI includeSetting up CUPTI lib64Configuration finished

This creates a canonical set of symbolic links to the Cuda libraries on yoursystem. Every time you change the Cuda library paths you need to run this stepagain before you invoke the bazel build command. For the cuDNN libraries, use'7.0' for R3, and '4.0.7' for R4.

Known issues

  • Although it is possible to build both Cuda and non-Cuda configs under the samesource tree, we recommend to runbazel clean when switching between these twoconfigs in the same source tree.

  • You have to run configure before running bazel build. Otherwise, the buildwill fail with a clear error message. In the future, we might consider makingthis more convenient by including the configure step in our build process.

Create the pip package and install

When building from source, you will still build a pip package and install that.

Please note that building from sources takes a lot of memory resources bydefault and if you want to limit RAM usage you can add--local_resources2048,.5,1.0 while invoking bazel.

$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package# To build with GPU support:$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg# The name of the .whl file will depend on your platform.$ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.11.0-py2-none-any.whl

Setting up TensorFlow for Development

If you're working on TensorFlow itself, it is useful to be able to test yourchanges in an interactive python shell without having to reinstall TensorFlow.

To set up TensorFlow such that all files are linked (instead of copied) from thesystem directories, run the following commands inside the TensorFlow rootdirectory:

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package# To build with GPU support:bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_packagemkdir _python_buildcd _python_buildln -s ../bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .ln -s ../tensorflow/tools/pip_package/* .python setup.py develop

Note that this setup still requires you to rebuild the//tensorflow/tools/pip_package:build_pip_package target every time you changea C++ file; add, delete, or move any python file; or if you change bazel buildrules.

Train your first TensorFlow neural net model

Starting from the root of your source tree, run:

$ cd tensorflow/models/image/mnist$ python convolutional.pySuccessfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.Extracting data/train-images-idx3-ubyte.gzExtracting data/train-labels-idx1-ubyte.gzExtracting data/t10k-images-idx3-ubyte.gzExtracting data/t10k-labels-idx1-ubyte.gzInitialized!Epoch 0.00Minibatch loss: 12.054, learning rate: 0.010000Minibatch error: 90.6%Validation error: 84.6%Epoch 0.12Minibatch loss: 3.285, learning rate: 0.010000Minibatch error: 6.2%Validation error: 7.0%......

Common Problems

If you encounter the following when trying to run a TensorFlow program:

ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory

Make sure you followed the GPU installationinstructions. If you built from source,and you left the Cuda or cuDNN version empty, try specifying them explicitly.

TensorFlow pip package depends on protobuf pip package version3.0.0b2. Protobuf's pip package downloaded fromPyPI(when running pip install protobuf) is a Python only library, that hasPython implementations of proto serialization/deserialization which can be10x-50x slower than the C++ implementation. Protobuf also supports a binaryextension for the Python package that contains fast C++ based proto parsing.This extension is not available in the standard Python only PIP package. We havecreated a custom binary pip package for protobuf that contains the binaryextension. Follow these instructions to install the custom binary protobuf pippackage:

# Ubuntu/Linux 64-bit:$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/protobuf-3.0.0-cp27-none-linux_x86_64.whl# Mac OS X:$ pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/protobuf-3.0.0-cp27-cp27m-macosx_10_11_x86_64.whl

And for Python 3:

# Ubuntu/Linux 64-bit:$ pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/protobuf-3.0.0-cp3-none-linux_x86_64.whl# Mac OS X:$ pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/protobuf-3.0.0-cp3-cp3m-macosx_10_11_x86_64.whl

Install the above package after you have installed TensorFlow via pip, as thestandardpip install tensorflow would install the python only pip package. Theabove pip package will over-write the existing protobuf package.Note that the binary pip package already has support for protobuf larger than64MB, that should fix errors such as these :

[libprotobuf ERROR google/protobuf/src/google/protobuf/io/coded_stream.cc:207] Aprotocol message was rejected because it was too big (more than 67108864 bytes).To increase the limit (or to disable these warnings), seeCodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.

Pip installation issues

Cannot import name 'descriptor'

ImportError: Traceback (most recent call last):  File "/usr/local/lib/python3.4/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>    from google.protobuf import descriptor as _descriptorImportError: cannot import name 'descriptor'

If you the above error when upgrading to a newer version of TensorFlow, tryuninstalling both TensorFlow and protobuf (if installed) and re-installingTensorFlow (which will also install the correct protobuf dependency).

Can't find setup.py

If, during pip install, you encounter an error like:

...IOError: [Errno 2] No such file or directory: '/tmp/pip-o6Tpui-build/setup.py'

Solution: upgrade your version of pip:

pip install --upgrade pip

This may require sudo, depending on how pip is installed.

SSLError: SSL_VERIFY_FAILED

If, during pip install from a URL, you encounter an error like:

...SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

Solution: Download the wheel manually via curl or wget, and pip install locally.

Operation not permitted

If, despite using sudo, you encounter an error like:

...Installing collected packages: setuptools, protobuf, wheel, numpy, tensorflowFound existing installation: setuptools 1.1.6Uninstalling setuptools-1.1.6:Exception:...[Errno 1] Operation not permitted: '/tmp/pip-a1DXRT-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib'

Solution: Add an --ignore-installed flag to the pip command.

Linux issues

If you encounter:

... "__add__", "__radd__",             ^SyntaxError: invalid syntax

Solution: make sure you are using Python 2.7.

Ubuntu build issue on Linux 16.04 when building with --config=cuda: build fail with cuda: identifier "__builtin_ia32_mwaitx" is undefined.

GitHub issue: https://github.com/tensorflow/tensorflow/issues/1066

Solution: Add the following compiler flags to third_party/gpus/crosstool/CROSSTOOL

cxx_flag: "-D_MWAITXINTRIN_H_INCLUDED"cxx_flag: "-D_FORCE_INLINES"

Mac OS X: ImportError: No module named copyreg

On Mac OS X, you may encounter the following when importing tensorflow.

>>> import tensorflow as tf...ImportError: No module named copyreg

Solution: TensorFlow depends on protobuf, which requires the Python packagesix-1.10.0. Apple's default Python installation only providessix-1.4.1.

You can resolve the issue in one of the following ways:

  • Upgrade the Python installation with the current version of six:
$ sudo easy_install -U six
  • Install TensorFlow with a separate Python library:

    • Using Virtualenv.
    • Using Docker.
  • Install a separate copy of Python via Homebrew orMacPorts and re-install TensorFlow in thatcopy of Python.

Mac OS X: OSError: [Errno 1] Operation not permitted:

On El Capitan, "six" is a special package that can't be modified, and thiserror is reported when "pip install" tried to modify this package. To fix use"ignore-installed" flag, ie

sudo pip install --ignore-installed six https://storage.googleapis.com/....

Mac OS X: TypeError:__init__() got an unexpected keyword argument 'syntax'

On Mac OS X, you may encounter the following when importing tensorflow.

>>> import tensorflow as tfTraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in <module>    from tensorflow.python import *  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 13, in <module>    from tensorflow.core.framework.graph_pb2 import *...  File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 22, in <module>    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'

This is due to a conflict between protobuf versions (we require protobuf 3.0.0).The best current solution is to make sure older versions of protobuf are notinstalled, such as:

$ pip install --upgrade protobuf

Mac OS X: Segmentation Fault when import tensorflow

On Mac OS X, you might get the following error when importing tensorflow in python:

>>> import tensorflowI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.dylib locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.dylib locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.dylib locally"import tensorflow" terminated by signal SIGSEGV (Address boundary error)

This is due to the fact that by default, cuda creates libcuda.dylib, but tensorflow tries to load libcuda.1.dylib.This can be resolved by create a symbolic link:

ln -sf /usr/local/cuda/lib/libcuda.dylib /usr/local/cuda/lib/libcuda.1.dylib
0 0
原创粉丝点击