Windows 10安装TensorFlow-gpu1.4 及CUDA8.0,cuDNN6.0,搞定了,包含安装方法和下载路径

42 篇文章 27 订阅
31 篇文章 3 订阅

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
共两个压缩包(解压后145M),此为其一 环境: windows10(X64) vs2015 Anaconda3-4.4.0-Windows-x86_64(python3.6) cuda_8.0.61_win10(basic) cuda_8.0.61.2_windows(Patch 2) cudnn-8.0 tensorflow1.30 pip install tensorflow-gpu后 Anaconda prompt中输入:import tensorflow时,报错:ImportError,需要用到这个库文件,分别copy至CUDA\v8.0 中三个目录下:bin,include,lib 具体错误一般如下: File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper return importlib.import_module(mname) File "C:\Anaconda3\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 986, in _gcd_import File "", line 969, in _find_and_load File "", line 958, in _find_and_load_unlocked File "", line 666, in _load_unlocked File "", line 577, in module_from_spec File "", line 906, in create_module File "", line 222, in _call_with_frames_removed ImportError: DLL load failed: The specified module could not be found. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 66, in from tensorflow.python import pywrap_tensorflow File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in _pywrap_tensorflow = swig_import_helper() File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper return importlib.import_module('_pywrap_tensorflow') File "C:\Anaconda3\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named '_pywrap_tensorflow' During handling of the above exception, another exception occurred: 。。。。。
对于安装 TensorFlow-GPU 1.14.0,您需要确保您的 Anaconda 环境已正确设置,并且已安装了正确版本的 CUDAcuDNN。 下面是安装步骤: 1. 首先,确保您已经成功安装了 Anaconda。如果还没有安装,请按照官方文档的指导进行安装。 2. 接下来,您需要安装 CUDA 10.0。您可以从 NVIDIA 官方网站下载适用于您的操作系统的 CUDA 安装程序,并按照指示进行安装。 3. 安装 CUDA 后,您需要安装 cuDNN 7.4。您需要先注册一个 NVIDIA 开发者账号,然后从 NVIDIA 开发者网站下载 cuDNN 安装包。根据您的操作系统和 CUDA 版本选择正确的版本,并根据 cuDNN 安装指南进行安装。 4. 安装CUDAcuDNN 后,打开 Anaconda Prompt(Windows)或终端(macOS/Linux)。 5. 创建一个新的环境并激活它: ``` conda create -n tf_gpu_env python=3.7 conda activate tf_gpu_env ``` 6. 在新环境中安装 TensorFlow-GPU 1.14.0: ``` pip install tensorflow-gpu==1.14.0 ``` 7. 安装完成后,您可以通过运行以下代码来验证 TensorFlow 是否正确安装并使用 GPU: ```python import tensorflow as tf print(tf.test.is_gpu_available()) ``` 如果输出为 True,则表示 TensorFlow 正确安装并且可以使用 GPU。 请注意,安装 TensorFlow-GPU 需要确保您的系统满足 CUDAcuDNN 的要求,并且您的 GPU 支持 CUDA。如果您遇到任何问题,请参考 TensorFlow 官方文档或在相关论坛上寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值