CUDA10.0、CUDNN(和cuda对应版本),tensorflow2.0在windows下的安装及配置

参考文章

全网最详细 | Windows 安装 TensorFlow2.0 GPU 详细教程

win10+1060显卡安装anaconda+CUDA10.1+pytorch+cuDNN+tensorflow-gpu

win10+GTX1050Ti+anaconda3+tensorflow1.14.0+cuda10.0+cudnn7.6.1.34(带GPU使用检测)

一、安装前的准备

切记tensorflow2.0对应的cuda版本是10.0,绝对不能下载错。
(1)查看自己N卡支持的CUDA版本,打开NVIDIA控制面板在左下角选择系统信息,然后点击组件,可以查看到支持cuda10.2版本了,向下兼容


(2)NVIDIA官网下载对应CUDA版本(没有账号需要注册账号)
CUDA下载地址:https://developer.nvidia.com/cuda-toolkit-archive

结合tensorflow2.0(目前最新)只支持到10.0版本,所以下载cuda10.0版本的
(3)CUDNN的下载(没有账号需要注册账号)
官网下载地址:https://developer.nvidia.com/rdp/cudnn-download

找到自己对应的CUDA版本,点击下载

二、安装过程
(1)安装CUDA
一开始的安装路径,选择OK(安装完成后路径会自动变化,所以这里路径选择默认就好)
选择自定义安装

取消勾选GeForce Experience ,如果电脑上本身就有Visual Studio Integration,要将这个取消勾选,避免冲突了

取消勾选Driver comonents,Display Driver这一行,前面显示的是Cuda本身包含的驱动版本是411.31,如果你电脑目前安装的驱动版本号新于Cuda本身自带的驱动版本号,那一定要把这个勾去掉。否则会安装失败(相同的话,就不用去取勾了)

CUDA的安装位置可以自定义,系统默认是在系统盘C盘,为了方便日后管理,可以安装到非系统盘的其他盘 ,我是默认安装路径,注意其中的samples放在了 C:\ProgramData\NVIDIA Corporation文件夹下面   

介绍一下:平时在使用电脑过程中,Windows系统会自动创建一个ProgramData文件夹,这里存放了公用软件信息和运行记录,对于统计电脑中的软件运行有很大的作用,但是由于它是隐藏文件,需要显示后才可被看到,下面跟大家介绍一下如何找到它吧。首先打开电脑进入c盘,我们发现找不到ProgramData文件夹。这时候不要着急,点击上方工具栏中的“工具”,在弹出的窗口中点击“文件夹选项”。在文件夹选项中点击“查看”,请查看页面。在查看中下拉找到“隐藏文件和文件夹”,将“显示隐藏的文件,文件夹和驱动器”进行勾选,点击应用即可。这样,回到c盘中即可找到ProgramData文件夹,查看相关的软件信息。
三、验证过程

打开路径 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin ,查看nvcc.exe

有这个nvcc.exe就说明CUDA安装已成功

打开路径 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\CUPTI\lib64,查看有没有cuti64_100.dll

有这个cuti64_100.dll就说明CUPT1已成功

(2)配置CUDNN
解压CUDNN后,将对应的bin、lib、include里面的文件与CUDA10.0对应的bin、lib、include进行合并。 

下面是放在一起,有的就不表示出来了,相同的迁移做法

(3)配置环境变量
安装完CUDA后,CUDA会自动添加到环境变量中

CUPTA和CUDNN还没有加进来,所以必须将它们添加到路径,这样使用Tensorflow的时候才不会报错

需要手动添加CUPTI和CUDNN的环境变量如下图:

(4)测试版本得到cuda是10.0的

(5)卸载cuda

控制面板中打开 【程序】 ——》 【程序和功能】

留下:NVIDIA的图形驱动程序、NVIDIA Physx系统软件、NVIDIA GeForce Experience;按照【安装时间】排序,依次卸载即可;控制面板中卸载完毕后,打开任何一个清理软件进行清理,清理卸载之后无用的注册表

三、 TensorFlow 2.0 安装与测试
安装tensorflow-gpu
>> pip install tensorflow-gpu默认会下载最新的稳定版,目前最新的为2.0版本
在Anaconda虚拟环境中测试一下 tensorflow是否安装成功

import tensorflow as tf
import torch
import os

# os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

a = tf.constant(1.)
b = tf.constant(2.)
print(a+b)

print('GPU:', tf.test.is_gpu_available())
print('GPU:',torch.cuda.is_available())

 测试成功,说明gpu版本已经安装成功

四、可能出现的问题
(1)显卡驱动、CUDA版本不一致的问题,需要按照前面的步骤查看当前显卡驱动所支持的CUDA版本,去NVIDIA官网下载对应版本的CUDA
(2)ImportError: Could not find 'cudart64_100.dll'错误  ,在这里一般是tf2.0目前只适配cuda10.0,如果是安装其他版本的cuda,就会出现这个问题。

tensorflow - 仅支持 CPU 的最新稳定版(建议新手使用)
tensorflow-gpu - 支持 GPU 的最新稳定版(适用于 Ubuntu 和 Windows)
tf-nightly - 仅支持 CPU 的预览每夜版(不稳定)
tf-nightly-gpu - 支持 GPU 的预览每夜版(不稳定,适用于 Ubuntu 和 Windows)
tensorflow==2.0.0-beta1 - 仅支持 CPU 的预览 TensorFlow 2.0 测试版(不稳定)
tensorflow-gpu==2.0.0-beta1 - 支持 GPU 的预览 TensorFlow 2.0 测试版(不稳定,适用于 Ubuntu 和 Windows)
-------------------------------------------------------------------------------------------------------------------------------

解决方案:

tensorflow遇到ImportError: Could not find 'cudart64_100.dll'错误解决

彻底解决tensorflow:ImportError: Could not find 'cudart64_90.dll'

Tensorflow报错“Could not find ‘cudart64_6.dll”

Windows下安装tensorflow GPU版本报错:OSError: [WinError 126] 找不到指定的模块/Could not find 'cudart64_90.dll'

我的解决方案:

tensorflow-gpu==2.0.0-beta1 - 支持 GPU 的预览 TensorFlow 2.0 测试版(不稳定,适用于 Ubuntu 和 Windows),该版本不稳定,卸载重装一个稳定版即可

1. 卸载
>> pip uninstall tensorflow-gpu
 
2. 重新下载安装稳定版
>> pip install tensorflow-gpu

测试成功,说明gpu版本已经安装成功

(3)tensorflow-gpu ImportError: DLL load failed:找不到指定的模块

错误原因:CUDA版本与Tensorflow版本冲突

解决方案:卸载CUDA10.1,重新装CUDA10.0,同时添加对应的CUDNN,具体操作方法如上

(4)ImportError: Nomodule named '_pywrap_tensorflow_internal'

错误原因:

CUDA10.1与tensorflow-gpu版本冲突

参考博客 windows下安装tensorflow过程中解决办法集合+ImportError: Nomodule named '_pywrap_tensorflow_internal'

解决方案:同问题(3)的解决方案

(5)tensorflow各个版本的CUDA以及Cudnn版本对应关系
 

自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.支持mkl,无MPI; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 配置信息: hp@dla:~/work/ts_compile/tensorflow$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.19.1 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Found possible Python library paths: /usr/local/lib/python3.5/dist-packages /usr/lib/python3/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: Do you wish to build TensorFlow with TensorRT support? [y/N]: y TensorRT support will be enabled for TensorFlow. Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]:/home/hp/bin/TensorRT-5.0.2.6-cuda10.0-cudnn7.3/targets/x86_64-linux-gnu Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apacha Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished 编译: hp@dla:~/work/ts_compile/tensorflow$ bazel build --config=opt --config=mkl --verbose_failures //tensorflow/tools/pip_package:build_pip_package 卸载已有tensorflow: hp@dla:~/temp$ sudo pip3 uninstall tensorflow 安装自己编译的成果: hp@dla:~/temp$ sudo pip3 install tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值