TensorFlow(3):windows 上面使用python3.6 安装tensorflow-gpu版本

版权声明:本文为博主原创文章,未经博主允许不得转载。博主地址:http://blog.csdn.net/freewebsys https://blog.csdn.net/freewebsys/article/details/81276120

1,关于tensorflow-gpu


https://www.python.org/downloads/windows/
版本需要特别的说明。
要不然安装会有问题。
首先,python不能是最新的版本,tensorflow 的升级速度还是跟不上python。
毕竟lib库很大,需要测试呢。
python 3.6 x64 的版本,3.7 不支持。
tensorflow 直接 pip 安装就行了。tensorflow-gpu-1.9.0
需要安装cuda lib,这个也要求是 64 - 9.0 版本

2,python-64-3.6 安装


安装的时候,选择自定义安装,需要安装到d盘。
因为安装lib啥的特别多,慢慢就把c 盘撑爆了。

安装第一步勾选上,【设置环境变量】,就可以了。
要是没有勾选,手动设置path到

d:\python\python36;D:\Python\Python36\Scripts

目录是:d:\python\python36\

再自己的主目录 如:c:/user/admin 增加文件 pip/pip.ini
内容:

[global] 
index-url = https://mirrors.aliyun.com/pypi/simple/ 

然后安装的资源就都走阿里啦,超级快,安装中好多问题都是网络问题。
使用ali的镜像,基本上没有啥问题了。

3,安装tensorflow-gpu


pip3 install tensorflow-gpu

运行报错:没有cuda:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "D:\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
    self_check.preload_check()
  File "D:\Python\Python36\lib\site-packages\tensorflow\python\platform\self_check.py", line 82, in preload_check
    % (build_info.cudart_dll_name, build_info.cuda_version_number))
ImportError: Could not find 'cudart64_90.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 9.0 from this URL: https://developer.nvidia.com/cuda-toolkit

4,安装cuda


https://developer.nvidia.com/cuda-90-download-archive

这里必须安装9.0 的版本,选择本地exe,这个网络国内还是不太好。
1.3 G。
里面包括了nvidia 的开发全家桶。

扫描二维码关注公众号,回复: 2922361 查看本文章

需要 visual studio ide 编译有些包,可以忽略。

还是报错:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "D:\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
    self_check.preload_check()
  File "D:\Python\Python36\lib\site-packages\tensorflow\python\platform\self_check.py", line 97, in preload_check
    % (build_info.cudnn_dll_name, build_info.cudnn_version_number))
ImportError: Could not find 'cudnn64_7.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 7 from this URL: https://developer.nvidia.com/cudnn

安装完成之后下载 cudnn
https://developer.nvidia.com/cudnn
需要注册才行。需要cudnn才行。
https://developer.nvidia.com/rdp/cudnn-archive
要使用 7.0 for 9.0 版本对上:

下载是个zip 文件夹,把相关dll 拷贝到bin目录 lib 目录就行。

-Copy \cuda\bin\cudnn64_7.dll to d:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
-Copy \cuda\ include\cudnn.h to d:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include
-Copy \cuda\lib\x64\cudnn.lib to d:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64

然后就都安装成功了:

https://stackoverflow.com/questions/48698536/tensorflow-gpu-import-tensorflow-importerror-could-not-find-cudnn64-7-dll
从这里看到的。

以后再windows 上面也可以使用gpu 进行运算了,加快训练速度。

4,总结


主要安装就是需要确定版本的问题。
使用python3.5 x64 使用 pip 安装 tensorflow-gpu
需要安装 cuda 9.0 x64
解压缩 cudnn 到 相应的 bin lib 目录。
然后就可以了,版本一定要一一对应才行。
下一步看看gpu的效果。

本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/81276120

博主地址是:http://blog.csdn.net/freewebsys

猜你喜欢

转载自blog.csdn.net/freewebsys/article/details/81276120