1、安装CUDA8.0 http://blog.csdn.net/u013591306/article/details/74909558其中更新源有可能失效,如果CUDA8.0安装出现问题更换国内其他更新源即可。
2、安装Cudnn5.1.10参照caffe安装过程中Cudnn的安装
3、安装bazel参照http://blog.csdn.net/u013591306/article/details/79024172
4、本文选用github源码安装tensorflow
(1)下载源码文件:
$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow
其中--recurse-submodules是获取tensorflow所需要的protobuf库(加该选项运行成功的话,可以不单独安装protobuf)
进入tensorflow文件跟目录中
(2)配置./configure
$ ./configure
安装过程中需要不断输入y/n进行配置确认,安装过程如下:
You have bazel 0.6.1 installed.
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python
Found possible Python library paths:
/opt/ros/indigo/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/home/dh/deeplearing/caffe/python
Please input the desired Python library path to use. Default is [/opt/ros/indigo/lib/python2.7/dist-packages]
#本文用的是python2.7,要用python3的上边两个输入要改为python3的运行方式和运行路径。
Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: Y
jemalloc as malloc support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: N
No Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: N
No Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: N
No XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with GDR support? [y/N]: N
No GDR support will be enabled for TensorFlow.
Do you wish to build TensorFlow with VERBS support? [y/N]: N
No VERBS support will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL support? [y/N]: N
No OpenCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: y
CUDA support will be enabled for TensorFlow.
Please specify the CUDA SDK version you want to use, e.g. 8.0. [Leave empty to default to CUDA 8.0]: 8.0
#这里输入的是CUDA版本号,可用cat /usr/local/cuda/version.txt命令查看,本文所用的是CUDA8.0。
Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 6.0]: 5.1.10
Please specify the location where cuDNN 5.1.10 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:/usr/local/cuda
#这里输入的是cuDNN版本号,可用cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2查看。
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]6.1
#这里输入的是显卡的计算能力去https://developer.nvidia.com/cuda-gpus上找对应显卡的计算能力,在3.1至7.1之间不等。
Do you want to use clang as CUDA compiler? [y/N]: N
nvcc will be used as CUDA compiler.
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: /usr/bin/gcc
Do you wish to build TensorFlow with MPI support? [y/N]: N
No MPI support will be enabled for TensorFlow.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=native
Add "--config=mkl" to your bazel command to build with MKL support.
Please note that MKL on MacOS or windows is still not supported.
If you would like to use a local MKL instead of downloading, please set the environment variable "TF_MKL_ROOT" every time before build.
Configuration finished
dh@dh:~/tensorflow$
(3)编译
①仅 CPU 支持,无 GPU 支持:
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
有 GPU 支持:
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
②生成 pip 安装包
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
(4)使用 PIP 工具安装
$ pip install /tmp/tensorflow_pkg/tensorflow-0.7.1-py2-none-linux_x86_64.whl
(5)测试tensorflow是否安装成功
python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>