ubuntu14.04_64位安裝tensorflow-gpu

第一步(可直接跳到第二步):安裝nvidia顯卡驅動

linux用戶能夠經過官方ppa解決安裝GPU驅動的問題。使用以下命令添加Graphic Drivers PPA:html

sudo add-apt-repository ppa:graphics-drivers/ppa  

而後更新源:python

sudo apt-get update  

而後去navidia官網查看最新的驅動版本號:navidia官網:http://www.geforce.cn/drivers
好比說驅動的最新版本號爲396,則執行以下指令:linux

sudo apt-get install nvidia-396 

最後安裝openGL支持:c++

sudo apt-get install mesa-common-dev  

第二步:安裝cuda-8.0(中間會默認安裝顯卡驅動)

若是直接執行:$  sudo apt-get install -y cuda  會報錯。正確使用方法爲。
官方網站下載:CUDA Toolkit 8.0。下載網址爲:https://developer.nvidia.com/cuda-downloads
linux,86_64,Ubuntu,14.04,deb[local]
 
而後執行以下指令:
$ sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb  
$ sudo apt-get update  
$ sudo apt-get install cuda 
這時在/usr/local目錄下產生一個cuda安裝的路徑叫"cuda-8.0"添加cuda到環境變量:
sudo vim /etc/profile  
添加內容:
export CUDA_HOME=/usr/local/cuda-8.0  
export PATH=$CUDA_HOME/bin:$PATH    
export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH 
使環境變量生效
source /etc/profile
檢驗是否安裝成功:查看GPU運行的進程
$ nvidia-smi  

第三步:下降gcc版本到5.0如下

查看gcc當前使用版本:
$ gcc --help
$ gcc --version #查看gcc版本號
最後一行爲 <file:///usr/share/doc/gcc-4.8/README.Bugs>. 使用的ubuntu14.04使用的是4.8版本 因此不用下降gcc版本

不然執行以下指令:
sudo apt-get install g++-4.9  
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20  
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10  
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20  
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10  
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30  
sudo update-alternatives --set cc /usr/bin/gcc  
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30  
sudo update-alternatives --set c++ /usr/bin/g++  

第四步:下載 cuDNN V5+ 庫文件並添加到cuda-8.0庫

解壓並將內容copy到/usr/local/cuda-8.0/include和lib64目錄中:ubuntu

cudann-8.0是目前爲止比較穩定的版本在更新tensorflow後(1.4.1- 指令: pip install --upgrade tensorflow-gpu 便可更新tensorflow)vim

在官網下載對應版本的*.tgz文件。windows

指令以下:api

sudo tar xvzf cudnn-8.0-linux-x64-v5.1.tgz  
sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include  
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64  
sudo chmod a+r /usr/local/cuda-8.0/include/cudnn.h /usr/local/cuda-8.0/lib64/libcudnn*   #分配包的權限  

第五步:安裝tensorflow

(1)Anaconda安裝tensorflow

下載:Anaconda2-4.3.1-Linux-x86_64.sh(https://repo.continuum.io/archive/)參考網址:https://www.cnblogs.com/willnote/p/6746499.htmlbash

bash Anaconda2-4.3.1-Linux-x86_64.sh

Anaconda倉庫鏡像

官方下載更新工具包的速度很慢,因此繼續添加清華大學 TUNA提供的Anaconda倉庫鏡像,在終端或cmd中輸入以下命令進行添加工具

$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
$ conda config --set show_channel_urls yes

備註:若是出現conda命令未找到,查看:https://www.cnblogs.com/chamie/p/10009193.html

Tensorflow安裝

在終端或cmd中輸入如下命令搜索當前可用的tensorflow版本

(能夠略掉)$ anaconda search -t conda tensorflow

Using Anaconda API: https://api.anaconda.org
Run 'anaconda show <USER/PACKAGE>' to get more details:
Packages:
     Name                      |  Version | Package Types   | Platforms      
     ------------------------- |   ------ | --------------- | ---------------
     HCC/tensorflow            |    1.0.0 | conda           | linux-64       
     HCC/tensorflow-cpucompat  |    1.0.0 | conda           | linux-64       
     HCC/tensorflow-fma        |    1.0.0 | conda           | linux-64       
     SentientPrime/tensorflow  |    0.6.0 | conda           | osx-64         
                                          : TensorFlow helps the tensors flow
     acellera/tensorflow-cuda  |   0.12.1 | conda           | linux-64       
     anaconda/tensorflow       |    1.0.1 | conda           | linux-64       
     anaconda/tensorflow-gpu   |    1.0.1 | conda           | linux-64       
     conda-forge/tensorflow    |    1.0.0 | conda           | linux-64, win-64, osx-64
                                          : TensorFlow helps the tensors flow
     creditx/tensorflow        |    0.9.0 | conda           | linux-64       
                                          : TensorFlow helps the tensors flow
     derickl/tensorflow        |   0.12.1 | conda           | osx-64         
     dhirschfeld/tensorflow    | 0.12.0rc0 | conda           | win-64         
     dseuss/tensorflow         |          | conda           | osx-64         
     guyanhua/tensorflow       |    1.0.0 | conda           | linux-64       
     ijstokes/tensorflow       | 2017.03.03.1349 | conda, ipynb    | linux-64       
     jjh_cio_testing/tensorflow |    1.0.1 | conda           | linux-64       
     jjh_cio_testing/tensorflow-gpu |    1.0.1 | conda           | linux-64       
     jjh_ppc64le/tensorflow    |    1.0.1 | conda           | linux-ppc64le  
     jjh_ppc64le/tensorflow-gpu |    1.0.1 | conda           | linux-ppc64le  
     jjhelmus/tensorflow       | 0.12.0rc0 | conda, pypi     | linux-64, osx-64
                                          : TensorFlow helps the tensors flow
     jjhelmus/tensorflow-gpu   |    1.0.1 | conda           | linux-64       
     kevin-keraudren/tensorflow |    0.9.0 | conda           | linux-64       
     lcls-rhel7/tensorflow     |   0.12.1 | conda           | linux-64       
     marta-sd/tensorflow       |    1.0.1 | conda           | linux-64       
                                          : TensorFlow helps the tensors flow
     memex/tensorflow          |    0.5.0 | conda           | linux-64, osx-64
                                          : TensorFlow helps the tensors flow
     mhworth/tensorflow        |    0.7.1 | conda           | osx-64         
                                          : TensorFlow helps the tensors flow
     miovision/tensorflow      | 0.10.0.gpu | conda           | linux-64, osx-64
     msarahan/tensorflow       | 1.0.0rc2 | conda           | linux-64       
     mutirri/tensorflow        | 0.10.0rc0 | conda           | linux-64       
     mwojcikowski/tensorflow   |    1.0.1 | conda           | linux-64       
     rdonnelly/tensorflow      |    0.9.0 | conda           | linux-64       
     rdonnellyr/r-tensorflow   |    0.4.0 | conda           | osx-64         
     test_org_002/tensorflow   | 0.10.0rc0 | conda           |                
Found 32 packages

選擇一個較新的CPU或GPU版本,如jjh_cio_testing/tensorflow-gpu的1.0.1版本,輸入以下命令查詢安裝命令

(能夠略掉)$ anaconda show jjh_cio_testing/tensorflow-gpu

Using Anaconda API: https://api.anaconda.org
Name:    tensorflow-gpu
Summary: 
Access:  public
Package Types:  conda
Versions:
   + 1.0.1

To install this package with conda run:
     conda install --channel https://conda.anaconda.org/jjh_cio_testing tensorflow-gpu

使用最後一行的提示命令進行安裝

$ conda install --channel https://conda.anaconda.org/jjh_cio_testing tensorflow-gpu==1.3.0

Fetching package metadata .............
Solving package specifications: .

Package plan for installation in environment /home/will/anaconda2:

The following packages will be SUPERSEDED by a higher-priority channel:

    tensorflow-gpu: 1.0.1-py27_4 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free --> 1.0.1-py27_4 jjh_cio_testing

Proceed ([y]/n)? 

conda會自動檢測安裝此版本的Tensorflow所依賴的庫,若是你的Anaconda缺乏這些依賴庫,會提示你安裝。由於我以前已經安裝過了,因此這裏只提示我安裝Tensorflow。輸入y並回車以後等待安裝結束便可

  • 能夠選擇次高版本的Tensorflow安裝,由於最新版本可能清華 TUNA的倉庫鏡像庫沒有及時更新,而官方更新鏈接老是失敗,我最開始選擇了jjhelmus/tensorflow-gpu的1.0.1版本,其餘依賴 庫清華 TUNA的倉庫鏡像有資源,而到最後jjhelmus/tensorflow-gpu版本的Tensorflow安裝包老是下載不下來,嘗試20屢次以後 換了一個1.0.0的版本,終於順利安裝成功

進入python,輸入

import tensorflow as tf 

若是沒有報錯說明安裝成功。

(2)PIP安裝tensorflow

安裝完CUDA 8 和 cuDNN 5後, 在終端輸入 sudo apt-get install libcupti-dev(參考:https://www.cnblogs.com/zengcv/p/6564517.html)

Ubuntu14.04默認安裝的Python2.7.6

先安裝Python庫

sudo apt-get install python-pip python-dev 

安裝tensorflow:

      (1)在線安裝 

                sudo pip install https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl 

   (2)下載安裝(因爲Ubuntu系統下,網上比較慢,能夠在windows下載。推薦這種安裝方法) 

               sudo pip install tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl 

    (下載地址:https://pypi.org/project/tensorflow-gpu/1.0.1/#files)

相關文章
相關標籤/搜索