1. 程式人生 > >Ubuntu16.04系統+GTX1050TI顯示卡的tensorflow1.6(GPU版)安裝-詳細圖文

Ubuntu16.04系統+GTX1050TI顯示卡的tensorflow1.6(GPU版)安裝-詳細圖文

前言

最近學習深度學習有一段時間了,遇到Google的tensorflow深度學習框架,實在是廣大深度學習愛好者的福音啊,然而,在安裝tensorflow框架的時候,我是踩坑無數,終於花了一天時間成功安裝了Google的最新版1.6版本的tensorflow的框架啊

一.必備軟硬體的下載

1.1 系統安裝:Ubuntu16.04版(64位)

注意:切記一定要是64位,不然安裝過程中會報異常

系統安裝詳情請自行百度

1.2 硬體驅動更新:NVIDA-384

首先,你要有一塊效能大於3的顯示卡,最好是GTX的顯示卡,個人推薦GTX(7,8,9,10系列),我的顯示卡是GTX1050TI,算是入門級別的。關於顯示卡驅動的更新:1.開啟terminal輸入以下指令:
sudo apt-get update

2.系統設定->軟體更新->附加驅動->選擇nvidia最新驅動(384)->應用更改

3.更新完硬體驅動,重啟電腦



1.3 CUDA-9.0下載

  tensorflow最新版本1.6版的,支援的比較好的搭配是CUDA-9.0+CUDNN7.0,切記一定要選好搭配,我曾將經踩坑,下了其他版本的CUDA和CUDNN,後面在安裝tensorflow的時候,出現各種無厘頭的BUG。

另外,CUDA一定要下載runfile格式的,切勿下載deb格式和其他格式的


1.4 CUDNN-7.0下載

剛才說了,tensorflow最新版本1.6版的,支援的比較好的搭配是CUDA-9.0+CUDNN7.0,因此,我們這裡所要用到的CUDNN是CUDNN7.0版本的

說明:

(1)CUDNN的下載需要註冊個賬號,並填寫相關問卷(問卷答案隨你開心就好)

(2)一定要選擇CUDN for LINUX版本的,不要選擇CUDNN  for Linux (Power8)版本的

(3)填寫完畢點選 I Agree To 前面的小方框,出現如下: 


二.安裝過程

2.1 CUDA-9.0的安裝

開啟terminal,具體指令:

1. cd 切換到剛才下載CUDA-9.0的目錄

cd /home/***(自己的使用者名稱)/download/ 

2.執行安裝命令 ,其中cuda_9.0.103_384.59_linux.run,改為你自己下載的cuda版本

sudo sh cuda_9.0.103_384.59_linux.run

3.執行安裝指令後,一直按回車鍵,你也可以按CTRL+C,跳過安裝說明

4.接下來,會有一系列的安裝提示讓您去確認,要注意的是有個讓你選擇是否安裝nvidia361驅動時,一定要選擇否

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?

因為前面我們已經安裝了更加新的顯示卡驅動nvidia384,所以這裡不要選擇安裝。其餘的都直接預設或者選擇是即可。 

Using more to view the EULA.
End User License Agreement
--------------------------


Preface
-------

The following contains specific license terms and conditions
for four separate NVIDIA products. By accepting this
agreement, you agree to comply with all the terms and
conditions applicable to the specific product(s) included
herein.


NVIDIA CUDA Toolkit


Description

The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references. The NVIDIA CUDA Toolkit
License Agreement is available in Chapter 1.


Default Install Location of CUDA Toolkit

Windows platform:

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?
(y)es/(n)o/(q)uit: n

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-8.0 ]:  

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y 

Enter CUDA Samples Location
 [ default is /home/kinny ]: 

Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/kinny ...
Copying samples to /home/kinny/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Installed in /home/kinny, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-8.0/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver

Logfile is /tmp/cuda_install_17494.log

2.2 設定環境變數

開啟terminal,具體指令如下:

1.開啟~/.bashrc:

sudo gedit ~/.bashrc

2.在~/.bashrc檔案末尾新增環境變數設定

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda-9.0

3.關閉~/.bashrc檔案,輸入指令讓其生效:

source ~/.bashrc

2.3測試CUDA是否生效

開啟terminal,依次輸入以下指令,如果顯示一些關於GPU的資訊則說明安裝成功

cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery  #由cuda-9.0由自己的版本決定
sudo make
sudo ./deviceQuery

2.4 安裝CUDNN-7.0 

1.開啟terminal,切換到剛才安裝CUDNN-7.0的目錄

cd /home/***(自己的使用者名稱)/download/ 

2.解壓剛才下載的CUDNN的壓縮檔案

tar xvzf cudnn-9.0-linux-x64-v7.tgz

3.複製解壓後的檔案,其中cuda-9.0可改為自己的版本

sudo cp cuda/include/cudnn.h /usr/local/cuda-9.0/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64

4.修改複製後的檔案許可權

sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h /usr/local/cuda-9.0/lib64/libcudnn*

2.5 python3 版本的pip安裝與升級

1.安裝

sudo apt-get install python3-pip

2.升級

sudo pip3 install --upgrade pip

2.6 tensorflow1.6 (GPU)的安裝

sudo pip3 install tensorflow-gpu

2.7 tensorflow測試是否安裝成功

$ python3
...
>>> 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
>>>
恭喜,安裝成功!!!