tensorflow源代碼方式安裝

  本文介紹tensorflow源代碼方式安裝。安裝的系統爲 Ubuntu 15.04。html

獲取TensorFlow源代碼

git clone --recurse-submodules https://github.com/tensorflow/tensorflow

使用 --recurse-submodules 選項來獲取 TensorFlow 須要依賴的 protobuf 庫文件。python

安裝 Bazel

  聽從如下 指令 來安裝 bazel 依賴。bazel 安裝文件:下載地址linux

  bazel 缺省須要使用JDK1.8,如你使用JDK1.7,請下載相應的安裝包。git

  安裝 Bazel 其餘所需依賴:github

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

  執行以下命令來安裝Bazel:shell

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

   記住把 PATH_TO_INSTALL.SH 替換爲你下載的Bazel安裝文件名,如:bash

./bazel-0.1.4-installer-linux-x86_64.sh  --user

安裝其餘依賴

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

配置安裝

  運行 tensorflow 根目錄下的 configure 腳本。這個腳本會要求你輸入 python 解釋器的安裝路徑,並容許你可選擇安裝CUDA庫。ui

  若是不安裝CUDA,則這一步主要是定位python和numpy頭文件所在位置:this

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

   若是要安裝CUDA,則除了指定 python 外,還需指定 CUDA 安裝位置:spa

./configure
Please specify the location of python. [Default is /usr/bin/python]:
Do you wish to build TensorFlow with GPU support? [y/N] y
GPU support will be enabled for TensorFlow

Please specify the location where CUDA 7.0 toolkit is installed. Refer to
README.md for more details. [default is: /usr/local/cuda]: /usr/local/cuda

Please specify the location where the cuDNN v2 library is installed. Refer to
README.md for more details. [default is: /usr/local/cuda]: /usr/local/cuda

Setting up Cuda include
Setting up Cuda lib64
Setting up Cuda bin
Setting up Cuda nvvm
Configuration finished

 

構建支持GPU的Tensorflow 

  在tensorflow 根目錄下執行以下命令:

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

$ 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]

Note that "--config=cuda" is needed to enable the GPU support.

相關文章
相關標籤/搜索