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 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/qq_30263737/article/details/84893898