ubuntu14.04系统中安装tensorflow(gpu版)

来源:互联网 发布:云计算的好处 编辑:程序博客网 时间:2024/05/23 23:40
原文:http://blog.csdn.net/u012969412/article/details/64502393

系统配置:ubuntu14.04 + GTX1060 + i7(7700K)

安装部署参考地址1:http://blog.csdn.net/zhouchao_fight/article/details/51517338

安装部署参考地址2(推荐):http://blog.csdn.net/zhaoyu106/article/details/52793183

安装前准备工作(离线安装)

官方下载:cuda-8.0 toolkit

github下载tensorflow*.whl文件:tensorflow_GPU_py2.7 (拉到最下面选择GPU+py2)

官方下载:cuDNNV5(需要注册登录官网)

一共3个文件放入U盘,在ubuntu实体机上读取安装。这些文件全部放在/usr/local/WYLdownload目录下

第一步:安装nvidia显卡驱动

Linux用户可以通过官方ppa解决安装GPU驱动的问题。使用如下命令添加Graphic Drivers PPA:

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. sudo add-apt-repository ppa:graphics-drivers/ppa   
然后更新源:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. sudo apt-get update  
然后去navidia官网查看最新的驱动版本号:navidia官网:http://www.geforce.cn/drivers
比如说驱动的最新版本号为375,则执行如下指令:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install nvidia-375  
最后安装openGL支持:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install mesa-common-dev  

第二步:安装cuda-toolkit-8.0并用其安装cuda-8.0

如果直接执行:$ sudo apt-get install -y cuda  会报错。正确使用方法为。
官方网站下载:CUDA Toolkit 8.0。下载网址为:https://developer.nvidia.com/cuda-downloads

然后执行如下指令:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb  
  2. $ sudo apt-get update  
  3. $ sudo apt-get install cuda  
这时在/usr/local目录下产生一个cuda安装的路径叫"cuda-8.0"添加cuda到环境变量:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. sudo vim /etc/profile  
添加内容:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. export CUDA_HOME=/usr/local/cuda-8.0  
  2. export PATH=$CUDA_HOME/bin:$PATH    
  3. export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH  
使环境变量生效
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. source /etc/profile  
检验是否安装成功:查看GPU运行的进程
参考测试网址:http://blog.csdn.net/masa_fish/article/details/51882183
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ nvidia-smi  

下载cuda测试用例:下载到~/cuda_examples目录下

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ cuda-install-samples-8.0.sh ~/cuda_examples  
运行测试用例:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ cd ~/cuda_examples/NVIDIA_CUDA-8.0_Samples  
  2. $ make  

第三步:降低gcc版本到5.0以下

查看gcc当前使用版本:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ gcc --help  
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ gcc --version #查看gcc版本号  
最后一行为 <file:///usr/share/doc/gcc-4.8/README.Bugs>. 使用的ubuntu14.04使用的是4.8版本 所以不用降低gcc版本

否则执行如下指令:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo apt-get install g++-4.9  
  2. $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20  
  3. $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10  
  4. $ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20  
  5. $ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10  
  6. $ sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30  
  7. $ sudo update-alternatives --set cc /usr/bin/gcc  
  8. $ sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30  
  9. $ sudo update-alternatives --set c++ /usr/bin/g++  

第四步:下载 cuDNN V5 库文件并添加到cuda-8.0库

到官网下载:cudnn-7.0-linux-x64-v3.0.8-prod.tgz
网址为:https://developer.nvidia.com/rdp/cudnn-archive

解压并将内容copy到/usr/local/cuda-8.0/include和lib64目录中:

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo tar xvzf cudnn-8.0-linux-x64-v5.1.tgz  
  2. $ sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include  
  3. $ sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64  
  4. $ sudo chmod a+r /usr/local/cuda-8.0/include/cudnn.h /usr/local/cuda-8.0/lib64/libcudnn*   #分配包的权限  

第五步:安装tensorflow

一、Anaconda安装tensorflow(不推荐conda目录和系统自带python目录冲突):

官方安装tensorflow说明:https://www.tensorflow.org/install

1、Create a conda environment named tensorflow to run a version of Python by invoking the following command:建立tensorflow运行环境

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ conda create -n tensorflow  

2、Activate the conda environment by issuing the following command:激活conda环境
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ source activate tensorflow  
3、Issue a command of the following format to install TensorFlow inside your conda environment:

$ pip install --ignore-installed --upgrade TF_PYTHON_URL
其中TF_PYTHON_URL是想要配置的tensorflow版本:
如:https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl  

4、从conda环境中退出:

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ source deactivate  

二、git安装tensorflow

1、克隆Tensorflow仓库
#安转Git支持:sudo apt-get install git

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo git clone --recurse-submodules https://github.com/tensorflow/tensorflow /usr/local/WYLdownload/tensorflow  
  2. $ pip install --upgrade setuptools pip  
git clone <版本库的网址> <本地目录名>
即:上述指令是将git上的tensorflow包下载到ubuntu系统的/usr/local/WYLdownload/tensorflow包下
2、配置configure参数
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo ./configure  

三、pip安装tensoflow

在文件目录下执行:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo pip install --ignore-installed --upgrade tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl  

四、Bazel安装tensorflow(如果选择用Bazel安装tensorfloe***.whl)

Bazel是一个类似于Make的工具,是Google为其内部软件开发的特点量身定制的工具,如今Google使用它来构建内部大多数的软件。
1、首先安装jdk1.8: http://blog.csdn.net/u012969412/article/details/58056270
但是bazel需要的jdk非以上jdk。需要oracle自己的jdk8包。
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo add-apt-repository ppa:webupd8team/java  
  2. $ sudo apt-get update  
  3. $ sudo apt-get install oracle-java8-installer  
2、安装Bazel依赖:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list  
  2. $ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -  
  3. $ sudo apt-get install python-numpy swig python-dev python-wheel  
3、安装源支持与bazel并更新bazel:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ sudo apt-get update   
  2. $ sudo apt-get install bazel  
  3. $ sudo apt-get upgrade bazel  

执行如下指令查看bazel是否安装完成:

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. $ bazel version  
往后略可以看官网
0 0
原创粉丝点击