2018年12月3日 星期一

利用Tensorflow GPU運算,Anaconda平台安裝步驟

電腦環境

OS: windows 10 pro
顯卡:Nvidia 1080ti
Visual Studio 2017
CUDA Tookit 10.0
cuDNN v7.3.1 Library for Windows 10

1. 檢查顯示卡是否支援

2. 安裝Install Visual C++ Build Tools

3. CUDA Toolkit 安裝

因為我的電腦是nVidia  1080ti的顯示卡,也更新了驅動程式 ,所以就直接安裝CUDA   Toolkit
CUDA Toolkit 10.0 Download 
版本:cuda_10.0.130_win10_network.exe
CUDA Toolkit

執行安裝,windows 10安裝時,我都習慣用以"系統管理員身分執行"避免權限不足導致安裝異常等情況
image.png

接著一直"下一步"到完成安裝。
image.png

[注意]安裝的過程可能會更新到舊版本的驅動程式,我因為舊版本無法支援雙螢幕,另手動在更新最新版本的。

有些教學文會加註說明要設定環境變數,但目前在windows 10的安裝過程就會自己協助加入,不需在手動加入了。

安裝完成重新開機。

4.安裝完後檢查CUDA版本

命令提示字元下nvcc --version指令
image.png

5.安裝 NVIDIA CUDA Deep Neural Network library (cuDNN)


下戴網址

image.png

我下載的版本:cuDNN v7.3.1 Library for Windows 10

解壓縮檔案cudnn-10.0-windows10-x64-v7.3.1.20.zip
image.png
將內容檔案複製到 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
取代目地檔案
image.png


6.安裝Anaconda

版本:Anaconda3-5.3.1-Windows-x86_64

安裝完成,以系統管理員執行Anaconda

建立python 3.6版本的環境,命名為tensorflow-gpu

image.png
image.png

pip install tensorflow-gpu
  Could not find a version that satisfies the requirement tensorflow-gpu (from versions: )
No matching distribution found for tensorflow-gpu
image.png
conda install tensorflow-gpu
Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - tensorflow-gpu
Use "conda info <package>" to see the dependencies for each package.
image.png

新版的Anaconda3-5.3.1 ,預設Python版本是3.7,因tensorflow-gpu目前只支援到3.6版本

因此需要將Python降版到3.6,我這裡是降到3.6.5
先查看所有版本,指令:conda search --full-name python
image.png

指令:conda install python=3.6.5

查看降版結果,指令:conda info
image.png

安裝tensorflow-gpu,指令:  pip install tensorflow-gpu
image.png
命令指示字元啟用環境,指令:activate tensorflow-gpu

查看是否成功

安裝tensorflow-gpu,指令:conda install tensorflow-gpu
image.png

安裝keras,指令:conda install keras
image.png

執行spyder,跑看看檢查GPU運算功能是否生效

import tensorflow as tf; 
print(tf.GIT_VERSION, tf.VERSION)

# Create TensorFlow object called tensor
hello_constant = tf.constant('Hello World!')

with tf.Session() as sess:
    # Run the tf.constant operation in the session
    output = sess.run(hello_constant)
    print(output.decode())# bytestring decode to string.
    
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))

from keras import backend as K
K.tensorflow_backend._get_available_gpus()

image.png

跑看看python檢查cpu元件是否有缺少的? 

image.png

沒有留言:

張貼留言