ubuntu14.04Lts安装Tensorflow(1)

时间:2022-02-03 06:27:42

ubuntu14.04Lts安装Tensorflow(1)

1、关于ubuntu系统的安装在此就不再详述,可见ubuntu安装

2、由于实验过程中使用到GPU,所以在安装完ubuntu14.04之后,安装相对应于GPU的显卡驱动,安装方法可见nvidia驱动安装

3、首先我们得从github上克隆Tensorflow库:

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

4、接下来安装Bazel

5、安装一些依赖

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

6、安装cuda

检测显卡的计算能力,Tensorflow要求显卡的计算能力大于3.5,查询显卡计算能力

下载和安装cuda toolkit7.5,cuda下载

安装依赖库:

$sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev 
安装cuda<pre name="code" class="plain">$ sudo dpkg -i cuda-repo-ubuntu1504-7-5-local_7.5-18_amd64
$ sudo apt-get update
$ sudo apt-get install -y cuda

 装好之后将cuda的路径bin和lib64写进环境变量。 

7、安装cudnn v5

下载cudnn v5。cudnn下载

tar xvzf cudnn-7.5-linux-x64-v5.tgz
sudo cp cudnn-7.5-linux-x64-v5/cudnn.h /usr/local/cuda/include
sudo cp cudnn-7.5-linux-x64-v5/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
8、配置Tensorflow

进入Tensorflow目录

$ ./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 which gcc nvcc should use as the host compiler. [Default is
/usr/bin/gcc]: /usr/bin/gcc-4.9

Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave
empty to use system default]: 7.5

Please specify the location where CUDA 7.5 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 use system
default]: 4.0.4

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

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\"]: 3.5

Setting up Cuda include
Setting up Cuda lib64
Setting up Cuda bin
Setting up Cuda nvvm
Setting up CUPTI include
Setting up CUPTI lib64
Configuration finished
9、构建GPU支持

$ bazel build -c opt --config=cuda //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]
10、问题
在配置Tensorflow时,会安装boringssl,由于网络的限制,无法从google上下载软件,需要从github中下载。

解决方案:打开/tensorflow/tensorflow/wokspca.bzl,修改commit和remote

commit = "053931e",remote = "https://github.com/google/boringssl",


以上是安装Tensorflow过程,本过程是由Tensorflow官网所提供,其他解决方案都是由github上的大神所提供。