Win10-CUDA10.0-Tensorflow-GPU安装流程

Win10-CUDA10.0-Tensorflow-GPU安装流程

前言:目前处于研究生阶段,研究方向是计算机视觉。首先自我检讨,由于懒惰,一直没安装Linux系统,始终在用Win10,这在程序员中属于战五渣行为。2018年间曾给我的另一台win10系统的RTX2060设备安装过一次tensorflow-gpu,当时整个安装过程踩了不少坑,最后才成功安装运行。今年新购入一台计算机(噢耶,解放算力),需要再次安装tensorflow-gpu,故写此文做记录。
首先列出我的硬件:
GPU:Geforece GTX1660Ti CPU:Intel Core™i5-9400

1.安装Anaconda
(1) 到anaconda官网(https://www.anaconda.com)下载安装包,下载完成后安装。
此处应注意请勿选Add Anaconda to my PATH environment variable,后续自己配置环境,否则容易出错,且出错后卸载很麻烦。
图1

(2) 计算机-高级系统设置-环境变量,在用户变量和系统变量-Path中,添加如下3个目录: D:\Anaconda3、 D:\Anaconda3\Scripts 、D:\Anaconda520\Library\bin
(3) 打开cmd,打开控制台,输入python,回车,出现如下信息,则安装成功。
图2
在控制台输入:conda --version可查看anaconda版本信息。
另外,对于win10系统,安装Anaconda的同时必须安装wget,否则后续在使用命令conda create --name python37 python=3.7创建除了base环境以外的其他环境时,会出现如下错误:
在这里插入图片描述
Win10环境下wget的安装非常简单,可参照此篇博客------
https://blog.csdn.net/qq_40962368/article/details/86772419

2.安装Visual Studio 2017
因为cuda10.0的运行需要VS2017,若不安装则CUDA也无法成功安装。
另外,Vistual Studio官网只提供VS最新版本(目前是vs2019),本人未曾试过vs2019与CUDA10是否匹配。
VS2017版可在网上搜索资源,找到后下载安装即可,过程简单,不多展开叙述。

3.安装CUDA与cuDNN
首先需要注册一个NVIDIA的账号,才能下载NVIDIA的CUDA与cuDNN。
不同GPU有着与之对应的CUDA版本。打开NVIDIA控制面板,查看与你的GPU对应的CUDA型号,如图
在这里插入图片描述
点击:帮助-系统信息-组件,就可查看对应的CUDA版本信息。我的CUDA版本就是CUDA10.0,如图:
在这里插入图片描述
确定CUDA版本后,下载CUDA :https://developer.nvidia.com/cuda-toolkit-archive
再下载与之对应的cuDNN版本:
https://developer.nvidia.com/rdp/cudnn-archive
在这里插入图片描述
下载完成后,首先安装CUDA,路径可以默认也可以自选。
解压cuDNN,发现其实只是三个文件夹。
进入CUDA的安装目录,如我的是: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0,在该目录下,把cuDNN的三个文件夹复制黏贴上
在这里插入图片描述
运行-cmd,输入nvcc -V,弹出CUDA版本信息,则CUDA安装成功,如图:
在这里插入图片描述
4.安装TensorFlow-gpu
首先创建一个python环境:
运行-cmd,输入conda create --name your_env_name python=3.7
此处name your_env_name是你创建的环境的命名,python=3.7是你想创建的的环境的python版本。
如,我想安装的tensorflow版本是1.12,则我需要安装python3.6,我想给该环境命名为python36,则我在命令窗口输入:
conda create --name python36 python=3.6
在这里插入图片描述
该环境安装完成后,以后想启动该环境则在cmd命令窗口下输入:
启动:activate python36
退出:conda deactivate
首先声明,若直接用pip下载安装tensorflow,大概率会出现各种情况不可知的错误(我一把血泪),故不采用直接pip install tensoflow-gpu这一方法。
下一步:下载编译好的tensoflow-gpu-1.12.0的轮子。这是一热心大佬自己编译的,为我等渣渣提供了极大方便,再次真诚感谢这位大佬。下载地址:https://github.com/fo40225/tensorflow-windows-wheel/blob/master/1.12.0/py36/GPU/cuda100cudnn73sse2/tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl
下一步,激活安装好的python3.6环境:activate python36
安装该轮子文件:
pip install 路径\tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl
例如我把该轮子文件放在桌面,则我的安装路径是:
pip install C:\Users\Administrator\Desktop\tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl
在这里插入图片描述
至此GPU版tensoflow就安装完啦!

5.测试Tensoflow
打开PyCharm-settings,把先前创建好的python环境加载为解释器
在这里插入图片描述
虽然Anaconda创建的叫虚拟环境,但从地址来看,虚拟环境是有实际地址的,就在Anaconda安装路径的envs文件夹下。
随意新建一个.py文件,输入以下代码,运行:
import tensorflow as tf
hello_world = tf.constant(‘hello,tensoflow-gpu’)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(hello_world))

结果:
在这里插入图片描述
红色字体说明该python解释器识别了计算机的GPU,并用GPU进行计算,至此测试完成。

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
自编译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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值