tensorflow-gpu、cuda、cudnn之间是有版本关系的,在不知道对应关系的情况下如何安装
第一步,安装python。
这里推荐使用anaconda安装,用过的人都说好。
第二步,pip install tensorflow
第三步,pip install tensorflow-gpu
这里要先安装tensorflow-gpu是因为,tensorflow-gpu、cuda、cudnn之间有版本关联。所以我们先安装tensorflow-gpu,然后运行tensorflow-gpu测试程序,必定会报错。按照“遇到问题解决问题”的思路,我们就可以根据错误提示安装对应的cuda版本!
比如:ImportError: Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 10.0 from this URL: https://developer.nvidia.com/cuda-90-download-archive
看到没有,报错信息里明确的提示了,安装CUDA 10.0,它给的链接是9.0版本的,不要下载!
安装完了之后重启电脑,继续运行测试程序,会继续报错: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
根据报错提示安装cudnn7版本64位,根据给出的链接,注册之后就可以下载了
把下载下来的压缩文件解压,并复制到cuda的安装目录下,cuda的默认安装目录为:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
至此安装完成,然后再次运行测试程序。OK
测试代码参考https://blog.csdn.net/william_hehe/article/details/79615894