首頁 > 軟體

Ubuntu 15.04下TensorFlow原始碼方式安裝

2020-06-16 17:38:08

本文介紹TensorFlow原始碼方式安裝。安裝的系統為 Ubuntu 15.04。

獲取TensorFlow原始碼

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

使用 --recurse-submodules 選項來獲取 TensorFlow 需要依賴的 protobuf 庫檔案。

安裝 Bazel

  遵從以下 指令 來安裝 bazel 依賴。bazel 安裝檔案:下載地址

  bazel 預設需要使用JDK1.8,如你使用JDK1.7,請下載相應的安裝包。

  安裝 Bazel 其他所需依賴:

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

  執行如下命令來安裝Bazel:

1
2
chmod +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

安裝其他依賴

1
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

構建支援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.


IT145.com E-mail:sddin#qq.com