1. 程式人生 > >Windows 10安裝TensorFlow-gpu1.4 及CUDA8.0,cuDNN6.0,搞定了,包含安裝方法和下載路徑

Windows 10安裝TensorFlow-gpu1.4 及CUDA8.0,cuDNN6.0,搞定了,包含安裝方法和下載路徑

Windows 10安裝TensorFlow-gpu1.4 及CUDA8.0,cuDNN6.0,搞定了

先說下我的最終版本:

Python 3.5.3;

tensorflow-gpu==1.4.0 ;

CUDA Toolkit 8.0 GA1 (Sept 2016), Online Documentation;

cuDNN v6.0(Download cuDNN v6.0 (April 27, 2017), for CUDA 8.0)

 

注意CUDA的版本是由TensorFlow決定的。具體如何對應,需要去TensorFlow官網看:https://www.tensorflow.org/install/install_windows 
https://www.tensorflow.org/install/install_windows#requirements_to_run_tensorflow_with_gpu_support(很抱歉,大陸打不開2018.9.10),還有個方法是,下載喜歡的TF版本,讓系統報錯提示你安裝合適的CUDA版本


安裝TensorFlow:pip install tensorflow-gpu==1.4.0

下載CUDA8.0 :https://developer.nvidia.com/cuda-toolkit-archive
CUDA Toolkit 8.0 GA1 (Sept 2016), Online Documentation
安裝方法:https://docs.nvidia.com/cuda/archive/8.0/cuda-installation-guide-microsoft-windows/index.html
路徑C:\Users\guang\AppData\Local\Temp\CUDA 
驗證CUDA:
控制欄:
C:\Users\guang>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sat_Sep__3_19:05:48_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44

下載cuDNN:https://developer.nvidia.com/rdp/cudnn-archive  需要註冊賬號
Download cuDNN v7.0.5 (Dec 5, 2017), for CUDA 8.0(注意切換到6.0,要不然跟著我找麻煩)
安裝cuDNN步驟,比較麻煩,注意看,主要就是把cuDNN三個檔案複製到CUDA對應資料夾下就行
安裝方法:https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#download-windows
第五步我沒有做,因為沒有對應的VS軟體
Include cudnn.lib in your Visual Studio project.
Open the Visual Studio project and right-click on the project name.
Click Linker > Input > Additional Dependencies.
Add cudnn.lib and click OK.

執行程式碼測試效果:
import tensorflow as tf
a = tf.random_normal((100, 100))
b = tf.random_normal((100, 500))
c = tf.matmul(a, b)
sess = tf.InteractiveSession()


報錯1:

OSError: [WinError 126] 找不到指定的模組。
ImportError: Could not find 'msvcp140.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. You may install this DLL by downloading Visual C++ 2015 Redistributable Update 3 from this URL: https://www.microsoft.com/en-us/download/details.aspx?id=53587
解決方案:
下載軟體:
https://www.microsoft.com/en-us/download/details.aspx?id=53587
64位電腦下載軟體vc_redist.x64.exe,雙擊安裝
vc_redist.x64.exe而不是  
vc_redist.x86.exe

x86和X64是什麼意思
x64 是指CPU是64位版本的。
x86 是指CPU是32位版本的。
如果你的CPU是64位的。可以安裝64位的,也可以安裝32位的,反過來只能安裝32位的。

報錯2:
ImportError: Could not find 'cudart64_80.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 8.0 from this URL: https://developer.nvidia.com/cuda-toolkit

下載軟體2:
https://developer.nvidia.com/cuda-toolkit
這一步是下載工具箱cuda-toolkit(其實就是CUDA),下載後是cuda_9.2.148_win10.exe格式,我明明裝的是CUDA8.0,符合這裡的要求。Download and install CUDA 8.0 from this URL奇怪了
後來我通過軟體search everthing找到了檔案cudart64_80.dll,然後把他新增到系統路徑,命名為:CUDA_PATH_cudart64_80,路徑為:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
重啟電腦解決了。

再次執行,再次報錯:
ImportError: Could not find 'cudnn64_6.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 6 from this URL: https://developer.nvidia.com/cudnn


找不到這個檔案:cudnn64_6.dll,我搜索了一下,確實沒有找到,他提示我安裝cuDNN的cuDNN 6,我突然想起來,自己裝了cuDNN 7(Download cuDNN v7.0.5 (Dec 5, 2017), for CUDA 8.0)
我無語了,官網自己說7.0也是配套CUDA8的嘛。沒辦法,按照提示來吧,下載Download cuDNN v6.0 (April 27, 2017), for CUDA 8.0,三個檔案複製到CUDA對應目錄裡,再次執行,顯示如下內容,成功了。說明我的GPU是GeForce GTX 1050 Ti,6個運算力,滿足3個就夠了,頻率:1.475,記憶體:4G,

 

歡迎關注《灣區人工智慧》公眾號

2018-09-11 09:16:26.582331: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2018-09-11 09:16:27.016004: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: 
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.4175
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.30GiB
2018-09-11 09:16:27.016603: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
[Finished in 2.4s]
 
--------------------- 
作者:灣區Python 
來源:CSDN 
原文:https://blog.csdn.net/BTUJACK/article/details/82843200 
版權宣告:本文為博主原創文章,轉載請附上博文連結!