搜索
您的当前位置:首页正文

tensorflow源码安装

来源:二三娱乐

安装tensorflow

下载tensorflow源文件

安装Bazel,Bazel是Google开源构建工具,类似于Make的工具,用来编译构建tensorflow

Bazel下载地址:

sudo apt-get install pkg-config zip g++zlib1g-dev unzip

chmod +x bazel-version-installer-os.sh

./bazel-version-installer-os.sh --user

export PATH="$PATH:$HOME/bin"

或者安装bazel with apt

If you want to use the JDK 7, please replacejdk1.8withjdk1.7and if youwant to install the testing version of Bazel, replacestablewithtesting.

sudo apt-get update&&sudo apt-get install bazel

Once installed, you can upgrade to a newer version of Bazel with:

sudo apt-get upgrade bazel

安装tensorflow其他的依赖

配置tensorflow,需要你指定相应文件的安装目录。cd进tensorflow源文件。

sudo ./configure

配置好,会出现以下内容:

Setting up Cuda include

Setting up Cuda lib64

Setting up Cuda bin

Setting up Cuda nvvm

Setting up CUPTI include

Setting up CUPTI lib64

Configuration finished

使用Bazel编译构建

bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer

bazel build-c opt /tensorflow/tools/pip_package:build_pip_package

bazel-bin/tensorflow/cc/tutorials_example_trainer--use_gpu

# Lots of output. This tutorial iteratively calculates the major eigenvalue of# a 2x2 matrix, on GPU. The last few lines look like this.000009/000005 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]000006/000001 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]000009/000009 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]

OK!

Test:

cd /home/lei/tensorflow/tensorflow/models/image/mnist

python convolutional.py

Installing TensorFlow from Sources

If the last paragraph didn't scare you off, welcome.  This guide explains

how to build TensorFlow on the following operating systems:

Ubuntu

Mac OS X

Determine which TensorFlow to install

You must choose one of the following types of TensorFlow to build and

install:

TensorFlow with CPU support only. If your system does not have a  NVIDIA® GPU, build and install this version. Note that this version of  TensorFlow is typically easier to build and install, so even if you  have an NVIDIA GPU, we recommend building and installing this version  first.

TensorFlow with GPU support. TensorFlow programs typically run  significantly faster on a GPU than on a CPU. Therefore, if your system  has a NVIDIA GPU and you need to run performance-critical applications,  you should ultimately build and install this version.  Beyond the NVIDIA GPU itself, your system must also fulfill the NVIDIA  software requirements described in one of the following documents:

Clone the TensorFlow repository

Start the process of building TensorFlow by cloning a TensorFlow

repository.

To clonethe latestTensorFlow repository, issue the following command:

The precedinggit clonecommand creates a subdirectorynamedtensorflow.  After cloning, you may optionally build aspecific branch(such as a release branch) by invoking thefollowing commands:

$cd tensorflow$git checkoutBranch# whereBranchis the desired branch

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

$git checkout r1.0

Prepare environment for Linux

Before building TensorFlow on Linux, install the following build

tools on your system:

bazel

TensorFlow Python dependencies

optionally, NVIDIA packages to support TensorFlow for GPU.

Install Bazel

Install TensorFlow Python dependencies

To install TensorFlow, you must install the following packages:

numpy, which is a numerical processing package that TensorFlow requires.

dev, which enables adding extensions to Python.

pip, which enables you to install and manage certain Python packages.

wheel, which enables you to manage Python compressed packages in    the wheel (.whl) format.

To install these packages for Python 2.7, issue the following command:

$sudo apt-get install python-numpy python-dev python-pip python-wheel

To install these packages for Python 3.n, issue the following command:

$sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel

Optional: install TensorFlow for GPU prerequisites

If you are building TensorFlow without GPU support, skip this section.

The following NVIDIAhardwaremust be installed on your system:

The following NVIDIAsoftwaremust be installed on your system:

The NVIDIA drivers associated with NVIDIA's Cuda Toolkit.

Finally, you must also installlibcupti-devby invoking the followingcommand:

$sudo apt-get install libcupti-dev

Next

Prepare environment for Mac OS

Before building TensorFlow, you must install the following on your system:

bazel

TensorFlow Python dependencies.

optionally, NVIDIA packages to support TensorFlow for GPU.

Install bazel

Install python dependencies

To install TensorFlow, you must install the following packages:

six

numpy, which is a numerical processing package that TensorFlow requires.

wheel, which enables you to manage Python compressed packages

in the wheel (.whl) format.

After installing pip, invoke the following commands:

$sudo pip install six numpy wheel

Optional: install TensorFlow for GPU prerequisites

After installing brew, install GNU coreutils by issuing the following command:

$brew install coreutils

If you want to compile tensorflow and have XCode 7.3 and CUDA 7.5 installed,

note that Xcode 7.3 is not yet compatible with CUDA 7.5.  To remedy this

problem, do either of the following:

Upgrade to CUDA 8.0.

Download Xcode 7.2 and select it as your default by issuing the following

command:

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

NOTE:Your system must fulfill the NVIDIA software requirements describedin one of the following documents:

Configure the installation

The root of the source tree contains a bash script namedconfigure. This script asks you to identify the pathname of allrelevant TensorFlow dependencies and specify other build configuration optionssuch as compiler flags. You must run this scriptpriortocreating the pip package and installing TensorFlow.

If you wish to build TensorFlow with GPU,configurewill askyou to specify the version numbers of Cuda and cuDNN. If severalversions of Cuda or cuDNN are installed on your system, explicitly selectthe desired version instead of relying on the system default.

Here is an example execution of theconfigurescript.  Note that yourown input will likely differ from our sample input:

If you toldconfigureto build for GPU support, thenconfigurewill create a canonical set of symbolic links to the Cuda librarieson your system.  Therefore, every time you change the Cuda library paths,you must rerun theconfigurescript before re-invokingthebazel buildcommand.

Note the following:

Although it is possible to build both Cuda and non-Cuda configs    under the same source tree, we recommend runningbazel cleanwhen    switching between these two configurations in the same source tree.

If you don't run theconfigurescriptbeforerunning thebazel buildcommand, thebazel buildcommand will fail.

Build the pip package

To build a pip package for TensorFlow with CPU-only support,

invoke the following command:

$bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

To build a pip package for TensorFlow with GPU support,

invoke the following command:

$bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

NOTE on gcc 5 or later:the binary pip packages available on the TensorFlow website are built with gcc 4, which uses the older ABI. To make your build compatible with the older ABI, you need to add-cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"to yourbazel buildcommand. ABI compatibility allows custom ops built against the TensorFlow pip package to continue to work against your built package.

Tip:By default, building TensorFlow from sources consumesa lot of RAM.  If RAM is an issue on your system, you may limit RAM usageby specifying--local_resources 2048,.5,1.0whileinvokingbazel.

Thebazel buildcommand builds a script namedbuild_pip_package.  Running this script as follows will builda.whlfile within the/tmp/tensorflow_pkgdirectory:

$bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Install the pip package

Invokepip installto install that pip package.The filename of the.whlfile depends on your platform.For example, the following command will install the pip packagefor TensorFlow 1.1.0 on Linux:

$sudo pip install /tmp/tensorflow_pkg/tensorflow-1.1.0-py2-none-any.whl

Validate your installation

Validate your TensorFlow installation by doing the following:

Start a terminal.

Change directory (cd) to any directory on your system other than thetensorflowsubdirectory from which you invoked theconfigurecommand.

Invoke python:

$python

Enter the following short program inside the python interactive shell:

>>>importtensorflowastf

>>>hello=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!

TensorFlow.

installation problems.

Common installation problems

The installation problems you encounter typically depend on the

operating system.  See the "Common installation problems" section

of one of the following guides:

Beyond the errors documented in those two guides, the following tablenotes additional errors specific to building TensorFlow.  Note that weare relying on Stack Overflow as the repository for build and installationproblems.  If you encounter an error message not listed in the precedingtwo guides or in the following table, search for it on Stack Overflow.  IfStack Overflow doesn't show the error message, ask a new question onStack Overflow and specify thetensorflowtag.

Top