参考文章
全网最详细 | 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)的解决方案