Use anaconda 3 mounted tensorflow 1.15.0 (win10 environment)

0, EDITORIAL

Tensorflow once before in fact installed, but due to computer virus, reinstall the system, put all removed all environments. Before forwarding in the blog tutorial an installation tensorflow others in win10, but the older version, so this time decided to write about.

1, Environment Description

This is a Win10 installation tensorflow under (1909) version, based on the anaconda installation. anaconda manage multiple isolated environments, independently of each other, more convenient.

2, installation anaconda

2.1 Download

Here select python 3.7 version of the download, the system according to their actual number of bits, download the corresponding version. download link

Anaconda download

2.2 Installation

In fact, the default installation process can be, there are two places to set about:

Anaconda installation 1

Anaconda installation 2

2.3 Check the installation results

Into the windows command line mode:
2.3.1 Detection Anaconda environment is installed successfully (see Anaconda version number):conda --version

2.3.2 currently installed to detect what environment variables:conda info --envs

2.3.3 version can be used to see which tensorflow currently are:conda search --full --name tensorflow

3, the new virtual environment

3.1 Environmental tfenv create and install python3.7:conda create --name tfenv python=3.7

3.2 to see if the installation was successful

2.3.2 can be used here in order to see whether the success of the installation environment

4, installation tensorflow

4.1 GPU version? CPU version?

Analyzing conditions result
Whether the video card is NVIDIA series graphics cards? It is = GPU; No = CPU
If NVIDIA series graphics cards, the ability to calculate how? 大于等于3.5 = GPU;小于3.5 = CPU

解释:

​ (1)首先,查看自己电脑显卡的型号。如果显卡是NVIDIA系列的,继续下面步骤;如果显卡不是NVIDIA系列的,直接装CPU版。

​ (2)然后,如果是NVIDIA系列的,则查询该显卡的计算能力。详见:查询计算能力。点开自己显卡对应的系列,查看自己显卡的GPU计算能力(即,Compute Capability)。如下图,显卡NVIDIA GTX 1050对应的计算能力为6.1。

​ (3)最后,到官网查询发布的GPU支持,查看硬件要求。本文查询时的标准是3.5(如下图)。如果计算能力≥3.5,可以装GPU版;相反<3.5的只能选择CPU版了。

​ (4)GPU和CPU两个版本没有太大的区别,只是计算的快慢问题,GPU版本的计算更快。

4.2 版本号如何选择?

​ 4.2.1 CPU版本的基本没有特别的限制,选择适合自己的就行。

​ 4.2.2 确认自己的显卡可以支持GPU版之后,Tensorflow-GPU版本的选择主要看两个指标:CUDA和cuDNN。需要下载安装CUDA和cuDNN

​ 4.2.3 **CUDA版本的选择:**它依赖于显卡的驱动程序版本,如下表,参考官方文档。与下表进行对照选择兼容的CUDA版本。

​ 如:我电脑的的驱动程序版本号为:417.22,所以对应的CUDA Toolkit版本应为10.0版本

​ 4.2.4 确认cuDNN对应于CUDA的版本。参照tensorflow官网给出的标准,如下表。然后从Nivdia官网下载对应版本的cuDNN。

版本 Python 版本 编译器 编译工具 cuDNN CUDA
tensorflow_gpu-1.13.0 3.5-3.6 MSVC 2015 update 3 Bazel 0.15.0 7 9
tensorflow_gpu-1.12.0 3.5-3.6 MSVC 2015 update 3 Bazel 0.15.0 7 9
tensorflow_gpu-1.11.0 3.5-3.6 MSVC 2015 update 3 Bazel 0.15.0 7 9
tensorflow_gpu-1.10.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 7 9
tensorflow_gpu-1.9.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 7 9
tensorflow_gpu-1.8.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 7 9
tensorflow_gpu-1.7.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 7 9
tensorflow_gpu-1.6.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 7 9
tensorflow_gpu-1.5.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 7 9
tensorflow_gpu-1.4.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 6 8
tensorflow_gpu-1.3.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 6 8
tensorflow_gpu-1.2.0 3.5-3.6 MSVC 2015 update 3 Cmake v3.6.3 5.1 8
tensorflow_gpu-1.1.0 3.5 MSVC 2015 update 3 Cmake v3.6.3 5.1 8
tensorflow_gpu-1.0.0 3.5 MSVC 2015 update 3 Cmake v3.6.3 5.1 8

​ 根据上图,根据对应的版本号,要安装对应的CUDA 和 cuDNN 的版本,对于版本号大于1.13的tensorflow-gpu版本,如1.14、1.15和2.0,要安装CUDA10.0,不要安装最新的CUDA10.1,安装后会提示缺少很多库文件,而导致GPU版本的tensorflow无法使用,如下图所示:

​ 4.2.5 根据上述的CUDA和cuDNN版本号,可以确定我们要安装的tensorflow版本号,如,根据我本机,CUDA安装10.0版本,cuDNN安装7.6.4版本,那我选择tensorflow-gpu-1.15版本安装。

4.3 安装CUDA以及cuDNN

4.3.1 下载安装CUDA Toolkit

CUDA下载链接。记得下载 local 版本(即完整版,network版为精简版)。

4.3.2 安装CUDA

​ 安装CUDA有两种方法:
​ 第一种:先装好对应CUDA需要的版本号,在装CUDA时选择不要重新安装驱动
​ 第二种:卸载掉已存在的驱动即确保系统上没有安装驱动,直接安装CUDA

​ 这里选择第二种方法,故先卸载掉原来的NVIDIA驱动。卸载完成后,打开安装程序,安装路径可以默认也可以自定义。之后点击ok就行。

​ 经过漫长的等待,来到了NVIDIA软件许可协议,同意许可协议,并继续

​ 选择高级

​ 默认全选

这里要记住安装路径,可以更改自己的路径

勾选,继续下一步

接下来就是漫长的等待……

​ 安装完成后,重启即可,系统会自动添加环境变量。

​ 验证是否安装成功:win + R,输入:powershell,执行命令:nvcc -V

4.3.3 下载 cuDNN

cuDNN下载地址 下载需要登录NVIDIA账号。

​ 下载完成后,会得到一个压缩包:cudnn-10.0-windows10-x64-v7.6.4.38.zip

4.3.4 安装cuDNN

​ 将下载的压缩包,解压并按下表的对应关系,将解压出来的文件复制到CUDA安装的对应路径下:(注意是路径中的文件)
​ 这里要根据自己的情况来,图中是我的解压和安装路径:

​ 添加环境变量:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64

4.4 安装tensorflow

​ 自带的源镜像站下载可能比较慢,这里可以选择修改为【清华大学镜像站】:
​ 打开Anaconda

​ 在这边更改为我们前面创建的虚拟环境tfenv,并点击旁边的按钮Channels:

​ 点击add,并添加【中国科技大学镜像站】的地址:https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/并回车,在这也可以将默认的镜像站删除,点击Update channels即可。

​ 打开命令提示符,激活3.1创建的虚拟环境tfenv:activate tfenv

​ 安装TensorFlow-GPU-1.15.0:pip install tensorflow-gpu==1.15.0 , 安装CPU版本的命令: pip install tensorflow==1.15.0 ,等于后面为要安装的tensorflow版本号

After successful installation, if .dll file can not be loaded situation occurs, you need to restart your computer!

4.5 Test

4.3.6.1 Test GPU is working, someone from the big brother of the code, installed version of the CPU can be skipped.

TRUE if the installation is successful.
Code:

import tensorflow as tf
a=tf.test.is_built_with_cuda()
b=tf.test.is_gpu_available(cuda_only=False,min_cuda_compute_capability=None)
print(a)
print(b)

4.3.6.2 test code

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

Output:b'Hello, TensorFlow!'

Published an original article · won praise 0 · Views 19

Guess you like

Origin blog.csdn.net/qq_41793080/article/details/104546053