本文介紹TensorFlow源代碼方式安裝。安裝的系統為 Ubuntu 15.04。
git clone --recurse-submodules https:
//github
.com
/tensorflow/tensorflow
使用 --recurse-submodules
選項來獲取 TensorFlow 需要依賴的 protobuf 庫文件。
遵從以下 指令 來安裝 bazel 依賴。bazel 安裝文件:下載地址
bazel 缺省需要使用JDK1.8,如你使用JDK1.7,請下載相應的安裝包。
安裝 Bazel 其他所需依賴:
1sudo
apt-get
install
pkg-config zip g++ zlib1g-dev unzip
執行如下命令來安裝Bazel:
1 2chmod
+x PATH_TO_INSTALL.SH
.
/PATH_TO_INSTALL
.SH --user
記住把 PATH_TO_INSTALL.SH 替換為你下載的Bazel安裝文件名,如:
1.
/bazel-0
.1.4-installer-linux-x86_64.sh --user
sudo
apt-get
install
python-numpy swig python-dev
運行 tensorflow 根目錄下的 configure
腳本。這個腳本會要求你輸入 python 解釋器的安裝路徑,並允許你可選擇安裝CUDA庫。
如果不安裝CUDA,則這一步主要是定位python和numpy頭文件所在位置:
1 2.
/configure
Please specify the location of python. [Default is
/usr/bin/python
]:
如果要安裝CUDA,則除了指定 python 外,還需指定 CUDA 安裝位置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16.
/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
在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.
http://xxxxxx/Linuxjc/1145176.html TechArticle