本文介绍tensorflow源代码方式安装。安装的系统为 Ubuntu 15.04。html
git clone --recurse-submodules https://github.com/tensorflow/tensorflow
使用 --recurse-submodules
选项来获取 TensorFlow 须要依赖的 protobuf 库文件。python
听从如下 指令 来安装 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
在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.