TensorFlow GPU version installed personal summary: Win10 + Python3.5 + CUDA 9.0.176 + cudnn v7.5.0.56 + TensorFlow 1.12.0

TensorFlow GPU version installed personal summary: Python3.5 + CUDA 9.0.176 + cudnn v7.5.0.56 + TensorFlow 1.12.0

Access to the machine learning for some time, after previous paragraph tensorflow configuration of GPU version when they were configured successfully pheasant online tutorial pit of tears, hardships, stroked a stroke ideas discovered that in fact is not so difficult.

Without further ado, straight into the topic.

Before 0. configuration you want to know

(1) tutorials assume you have installed the anaconda
(2) understand the concept of "environment". Configuration based Python3.5 environment, but the environment is often white is the default base, chances are the default Python version 3.7 which is that you check with the wrong go
(3) install CUDA most tedious part is that, Python, tensorflow, CUDA, cudnn must strictly correspond to the four versions , go wrong step would be to check with a couple of weeks a lot of people
(4) Remember, configure CUDA and high-low version is compatible with versions of this argument does not exist

1. Configure Python3.5 environment

(1) into the interface anaconda - Left-click environment-- environment found only one Base (root) , as shown below. The base environment it means the system default to a Python environment you create, of course, the default is the highest installed version of Python, which is why we need to create a safe environment.
PS: I've been under the Python3.5 is configured environment, it is now the default does not exist just fine haha
Here Insert Picture Description
(2) below Click Create, to create a new environment , as shown below, name is the name of the environment that he be named anything (some this step tutorial to say directly named as tensorflow, personal feeling is not very good), drop-down selection under the Python version 3.5, click create to create a complete environment
PS: this step is to wait a few minutes, because creating the environment need to download some base package
Here Insert Picture Description
(3) to this column is switched to installed, to view a variety of support packages have been installed, if you do not know there are a lot of packages are displayed, then congratulations you successful environment configuration
PS: If this step error, is not before you check to create the same environment name had the same environment (if you are now a second time or the third time configuration). To find the root of the anaconda installation, advance to the next envs folder, if you see Python3.5 folder decisively enough to remove it
Here Insert Picture Description

2. Install CUDA9.0

(1) download the corresponding version of CUDA
CUDA installed the most complicated place that he asked Python, CUDA, cudnn, tensorflow four in one version, strict correspondence. Specific comparison table below:
Here Insert Picture Description
To put it plainly, as long as you find a combination of a run up on the line. (But the problem is to find a combination of these times you might step on a pile pit ha ha ha ha) adopt me here is that under Win10 environment, Python3.5 + CUDA 9.0.176 + TensorFlow 1.12.0 combination + cudnn v7.5.0.56 .

CUDA9.0的安装包地址在https://developer.nvidia.com/cuda-toolkit-archive自寻
cudnn7安装包地址:https://developer.nvidia.com/cudnn(需要注册英伟达账号,嫌麻烦直接拿文章末尾的资源)

如果下载过程中速度过慢或者直接下载失败的话,解决方案也很简单:下载的时候出来两个选项,本地安装包和在线安装包,选择在线安装即可。(他俩的区别就是本地安装包会直接把安装包整体下载到你电脑上,大小1GB左右,在线安装包可能只有十几MB,下载很快就完成了,二者后续安装过程也基本一样)
Here Insert Picture Description

(2)临时解压:双击下载下来的文件,选择临时解压路径

这一步特别重要,切记不要把临时解压路径和正式安装路径全都放在一个文件夹里,因为正式安装完毕后临时文件夹整体会自动被删除,你都放一起等于白安一遍。

默认是系统盘的路径,我这里改成D盘(系统盘空间宝贵哈哈哈哈),新建文件夹temp
Here Insert Picture Description

(3)正式安装:

勾选同意
Here Insert Picture Description

选择自定义安装
Here Insert Picture Description

全部勾选(有的教程说只勾选第一个就行,保险起见这里先勾上,大家以后可以自行尝试)
Here Insert Picture Description

选择安装路径:默认还是系统盘,我这里仍然改成D盘,新建文件夹CUDA9.0
这里一定要区分开,不要放到刚才的临时文件夹temp里!
Here Insert Picture Description

正在联网下载中,点杯奶茶等着吧哈哈哈

PS:如果是本地安装的话这一步就直接开始安装了
! [Insert Picture description here] (https://img-blog.csdnimg.cn/20200302120601630.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTkxODQ1Nw==,size_16,color_FFFFFF,t_70
之后基本就没什么问题了,如果提示VS2010有问题也不用管。

3.安装cudnn7

cudnn相当于CUDA的一个补丁,官网需要注册才能下载,如果嫌麻烦直接到文末找我上传的资源就行

(1)解压一下cudnn压缩包,发现里面有几个文件夹。人家这么命名的意思是告诉你,对应文件夹下的内容应该放到CUDA安装目录的同名文件夹下。(这点很多教程写的都不是很好,以下我会演示一下正确的做法)
Here Insert Picture Description
(2)放置对应文件

举个栗子:bin点开以后发现有这么个玩意
Here Insert Picture Description
打开CUDA 9.0安装目录下的bin文件夹,把这个给扔进去进行了
Here Insert Picture Description

同理:include点开只有这一个头文件
Here Insert Picture Description
找到CUDA9.0安装目录底下的include文件夹,扔到里面
Here Insert Picture Description

lib也是一样,只不过下面有个x64文件夹,继续点开
Here Insert Picture Description
然后进入到CUDA9.0安装目录下对应的./lib/x64下面,扔进去,大功告成
Here Insert Picture Description

4.配置环境变量

这一步网上的教程也是说的鱼龙混杂,我在各个教程之间取了个并集,测试可行,直接上我的图

大家直接在系统变量里面改就行,不用管用户变量。

绿圈里面的两个变量是你安装好CUDA9.0以后自动建立的,其余需要自己手动添加。(我这里演示的是我自己装那一次配置好的环境变量,当时文件夹命名没加9.0,红字补上。这一步的变量值就是我们安装好的CUDA 9.0路径,每个人的可能都不同,以CUDA9.0文件路径为准)
Here Insert Picture Description

改完这几个以后,进入到系统变量的PATH下,同理,环境变量值根据大家自己的CUDA9.0文件夹实际路径来写。
Here Insert Picture Description

配置完这一步整个CUDA的安装就完毕了,下一步安装Tensorflow的GPU版本

5.安装tensorflow的GPU版本

(1)进入到anaconda prompt,默认是base环境
Here Insert Picture Description
(2)输入activate Python3.5,激活刚刚配置好的Python3.5环境,以后所有的安装都在这个环境下进行
Here Insert Picture Description
(3)直接pip install tensorflow-gpu==1.12.0,按理来说会慢慢下载,如果一次不成功多试两次,再不行改用指令conda install tensorflow-gpu==1.12.0,这里就不演示结果了,如果安装成功以后会出现提示。

PS:这一步切记不要把tensorflow CPU和GPU 放在同一个环境下安装,否则会报错。
Here Insert Picture Description
(4)回到anaconda里, 点进去Python3.5环境,右上角框框设置为not installed,搜索Spyder进行安装(或者其他你喜欢的编译器,但切记要安装在Python3.5环境下),我这里已经安装过所以没有显示
Here Insert Picture Description

PS:这一步也是很多新人容易跳的坑,安装完tensorflow觉得万事大吉直接从桌面找到Spyder点进去,一运行代码报错,其实是因为你点进去的Spyder是base环境下的,可能根本没安上tensorflow也可能你之前安的是CPU版本的。所以需要在Python3.5环境下单独安装一个Spyder,安装完成后在anaconda下能看到两个Spyder,点进去标着Python3.5的才是你GPU环境下可用的编译器,如下图所示
Here Insert Picture Description

6.测试是否安装成功

#测试代码1
import tensorflow as tf
print(tf.test.is_built_with_cuda())

#测试代码2
import tensorflow as tf
tf.test.is_gpu_available()


#测试代码3
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

#测试代码4
import tensorflow as tf
a = tf.constant([1.,2.,3.,4.,5.,6.], shape=[2,3], name='a')
b = tf.constant([1.,2.,3.,4.,5.,6.], shape=[3,2], name='b')
c = tf.matmul(a,b)
with tf.Session(config = tf.ConfigProto(log_device_placement=True)) as sess:
    print(sess.run(c))

The code is collected from the Internet to a collection of several different versions of the test code, any run through the instructions on the GPU version tensorflow completely successful installation (usually 4 code should be run through the same time, if the installation procedure in question should be four full error codes)

CUDA first piece of code to detect whether the installation is successful, the output is: True represents no problem

The second paragraph of code detection GPU is available, the output is: True represents no problem

Third paragraph of the code lists all available devices, output should indicate if there is nothing wrong on the GPU

Code Default fourth paragraph GPU retrieval operation, as long as no error it can output no problem

Released two original articles · won praise 1 · views 31

Guess you like

Origin blog.csdn.net/weixin_41918457/article/details/104606009