tensorflow源碼安裝

安裝tensorflow

下載tensorflow源文件

Gitclone--recurse-submoduleshttps://github.com/tensorflow/tensorflow

安裝Bazel,Bazel是Google開源構(gòu)建工具氮采,類似于Make的工具,用來編譯構(gòu)建tensorflow

http://bazel.io/docs/install.html

Bazel下載地址:

https://github.com/bazelbuild/bazel/releases(bazel-0.2.2b-installer-linux-x86_64.sh)

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

sudo apt-get install build-essential openjdk-8-jdk python zip unzip

./compile.sh install

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

或者安裝bazel with apt

Using Bazel custom APT repository (recommended)

1. Add Bazel distribution URI as a package source (one time setup)

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -

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

2. Install and update Bazel

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

如果使用mpi, 修改tensorflow/contrib/mpi_collectives/BUILD,加一行

“//tensorflow/stream_executor酿傍,”

```

/tensorflow/contrib/mpi_collectives/BUILD

@@ -53,6 +53,7 @@ tf_custom_op_library(

":mpi_defines",

":mpi_message_proto_cc",

"http://third_party/mpi",

(+) "http://tensorflow/stream_executor",

```

安裝tensorflow其他的依賴

sudo apt-get install python-numpy swig python-dev python-wheel

配置tensorflow吠架,需要你指定相應(yīng)文件的安裝目錄揖曾。cd進(jìn)tensorflow源文件。

?./configure

使用Bazel編譯構(gòu)建

# 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/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

# 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

```

https://www.tensorflow.org/install/install_sources#install_the_pip_package

Installing TensorFlow from Sources

This guide explains how to build TensorFlow sources into a TensorFlowbinary and how to install that TensorFlow binary.? Note that we providewell-tested, pre-built TensorFlow binaries for Linux, Mac, and Windowssystems. In addition, there are pre-built TensorFlowdocker images.So, don't build a TensorFlow binary yourself unless you are verycomfortable building complex packages from source and dealing withthe inevitable aftermath should things not go exactly as documented.

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

We don't officially support building TensorFlow on Windows; however, you may tryto build TensorFlow on Windows if you don't mind using the highly experimentalBazel on WindowsorTensorFlow CMake build.

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:

Installing TensorFlow on Ubuntu

Clone the TensorFlow repository

Start the process of building TensorFlow by cloning a TensorFlow

repository.

To clonethe latestTensorFlow repository, issue the following command:

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

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

Next, you must prepare your environment forLinuxorMac OS

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

If bazel is not installed on your system, install it now by followingthese directions.

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:

GPU card with CUDA Compute Capability 3.0 or higher.? SeeNVIDIA documentationfor a list of supported GPU cards.

The following NVIDIAsoftwaremust be installed on your system:

NVIDIA's Cuda Toolkit (>= 7.0). We recommend version 8.0.? ? For details, seeNVIDIA's documentation.? ? Ensure that you append the relevant Cuda pathnames to theLD_LIBRARY_PATHenvironment variable as described in the? ? NVIDIA documentation.

The NVIDIA drivers associated with NVIDIA's Cuda Toolkit.

cuDNN (>= v3). We recommend version 5.1. For details, seeNVIDIA's documentation,? ? particularly the description of appending the appropriate pathname? ? to yourLD_LIBRARY_PATHenvironment variable.

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

$sudo apt-get install libcupti-dev

Next

After preparing the environment, you must nowconfigure the installation.

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

If bazel is not installed on your system, install it now by followingthese directions.

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.

You may install the python dependencies using pip. If you don't have pipon your machine, we recommend using homebrew to install Python and pip asdocumented here.If you follow these instructions, you will not need to disable SIP.

After installing pip, invoke the following commands:

$sudo pip install six numpy wheel

Optional: install TensorFlow for GPU prerequisites

If you do not have brew installed, install it by followingthese instructions.

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:

Installing TensorFlow on Linux

Installing TensorFlow on Mac OS

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:

$cd tensorflow# cd to the top-level directory created$

./configure

Please specify the location of python. [Default is /usr/bin/python]:/usr/bin/python2.7

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:Do you wish to use jemalloc as the malloc implementation? [Y/n]jemalloc enabledDo you wish to build TensorFlow with Google Cloud Platform support? [y/N]No Google Cloud Platform support will be enabled for TensorFlowDo you wish to build TensorFlow with Hadoop File System support? [y/N]No Hadoop File System support will be enabled for TensorFlowDo you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]No XLA JIT support will be enabled for TensorFlowFound possible Python library paths:? /usr/local/lib/python2.7/dist-packages? /usr/lib/python2.7/dist-packagesPlease input the desired Python library path to use.? Default is [/usr/local/lib/python2.7/dist-packages]Using python library path: /usr/local/lib/python2.7/dist-packagesDo you wish to build TensorFlow with OpenCL support? [y/N] NNo OpenCL support will be enabled for TensorFlowDo you wish to build TensorFlow with CUDA support? [y/N] YCUDA support will be enabled for TensorFlowPlease specify which gcc should be used by nvcc 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

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 --config=mkl-dnn //tensorflow/tools/pip_package:build_pip_package

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

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_packag

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!

If you are new to TensorFlow, seeGetting Started with

TensorFlow.

If the system outputs an error message instead of a greeting, seeCommon

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:

Installing TensorFlow on Linux

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.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末钓丰,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子每币,更是在濱河造成了極大的恐慌携丁,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,839評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件脯爪,死亡現(xiàn)場離奇詭異则北,居然都是意外死亡矿微,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,543評論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來搜贤,“玉大人枚驻,你說我怎么就攤上這事∧缺樱” “怎么了?”我有些...
    開封第一講書人閱讀 153,116評論 0 344
  • 文/不壞的土叔 我叫張陵方篮,是天一觀的道長名秀。 經(jīng)常有香客問我,道長藕溅,這世上最難降的妖魔是什么匕得? 我笑而不...
    開封第一講書人閱讀 55,371評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮巾表,結(jié)果婚禮上汁掠,老公的妹妹穿的比我還像新娘。我一直安慰自己集币,他們只是感情好考阱,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,384評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著鞠苟,像睡著了一般乞榨。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上当娱,一...
    開封第一講書人閱讀 49,111評論 1 285
  • 那天吃既,我揣著相機(jī)與錄音,去河邊找鬼趾访。 笑死态秧,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的扼鞋。 我是一名探鬼主播申鱼,決...
    沈念sama閱讀 38,416評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼云头!你這毒婦竟也來了捐友?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,053評論 0 259
  • 序言:老撾萬榮一對情侶失蹤溃槐,失蹤者是張志新(化名)和其女友劉穎匣砖,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,558評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡猴鲫,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,007評論 2 325
  • 正文 我和宋清朗相戀三年对人,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片拂共。...
    茶點(diǎn)故事閱讀 38,117評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡牺弄,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出宜狐,到底是詐尸還是另有隱情势告,我是刑警寧澤,帶...
    沈念sama閱讀 33,756評論 4 324
  • 正文 年R本政府宣布抚恒,位于F島的核電站咱台,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏俭驮。R本人自食惡果不足惜回溺,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,324評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望表鳍。 院中可真熱鬧馅而,春花似錦、人聲如沸譬圣。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,315評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽厘熟。三九已至,卻和暖如春维哈,著一層夾襖步出監(jiān)牢的瞬間绳姨,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,539評論 1 262
  • 我被黑心中介騙來泰國打工阔挠, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留飘庄,地道東北人。 一個月前我還...
    沈念sama閱讀 45,578評論 2 355
  • 正文 我出身青樓购撼,卻偏偏與公主長得像跪削,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子迂求,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,877評論 2 345

推薦閱讀更多精彩內(nèi)容