TensorFlow-gpu安装教程(从零开始) win10+VS2015+CUDA10+cuDNN7.3+python3.6+TensorFlow1.12

背景

研一现在开始要准备开题,科研项目与图像处理有关。打算用深度学习来试一试。这周先试着搭一下环境。因为是刚开始,所以想着先在自己笔记本上跑一跑试试看。所以就在win10下先试一试吧。参考一些别人的教程。自己搭的时候没想到竟然搭了两天。(走了不少弯路踩了不少坑)。写这篇文章的一个目的也是以后再搭的时候省的自己忘了…

配置及准备工作

计算机配置

  1. windows 10 64位
  2. NVIDIA GeForce GTX 960M

所需软件

  1. Anaconda3(python3.6)
  2. PyCharm
  3. VS2015
  4. CUDA10
  5. cuDNN7.3
  6. tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl

下载及安装

  1. Anaconda3
    !Anaconda里面自带python,不用再单独下载python了!
    Anaconda通俗来说就是一个管理python各种内置包(包括本文中要用到的TensorFlow)的库。官网下载的只有最新版本,也就是基于python3.7的。目前最新版的tensorflow是支持3.7了,不过3.6版本的python还是最经典的,很多项目和教程也都是基于3.6的。所以推荐还是用3.6吧。省心哈哈。之前版本的Anaconda可以在https://repo.anaconda.com/archive/这个网址下。注意这个有很多个版本。基于我的笔记本。我选择win10,64位的版本(Anaconda3-5.2.0)。exe文件下载下来直接安装。在这里插入图片描述
    安装过程这里就不做叙述了,具体设置可以参考 https://www.jianshu.com/p/62f155eb6ac5
    里面各个操作系统的安装都有提到。

!!!(pip下载设置的Anaconda源别用国内清华或者其他的镜像源了!!!不能用啦。可以用清华的pypi的)!!!
https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
怎么设置前面的文章应该有提到。

  1. pycharm
    python自带了一个解释器IDLE用来执行.py脚本,但是却不利于我们书写调试大量的代码。常见的是用notepade++写完脚本,再用idle来执行,但却不便于调试。PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试、语法高亮、Project管理、代码跳转、智能提示、自动完成、单元测试、版本控制。此外,该IDE提供了一些高级功能,以用于支持Django框架下的专业Web开发。将anaconda中的python.exe集成到pycharm中,便可以在使用pycharm的过程中使用到所有anaconda的包了。
    下载及安装可以参考这篇博客 https://www.cnblogs.com/yuxuefeng/articles/9235431.html
    另外!pycharm分为专业版和社区版,社区版是免费的专业版要付费激活。正常来说社区版就够用了所以为了版权建议大家用社区版就好了。如果确实有需要也可以付费购买专业版。(当然也有破解方法哈哈)。下载的版本都是英文的。所以有需要的同学也可以参考这篇文章
    https://blog.csdn.net/u014044812/article/details/78727496
    来进行破解和汉化。

  2. VS2015
    安装VS这一步必须要在cuda安装之前,否则会导致cuda安装错误!!
    按照道理来说只要是高于2015版本的VS都应该可以,我之前电脑上就是VS2017,之前看的别人的文章也是有各种版本的VS。不过因为本人在装的时候老出现问题。索性卸载了2017装了2015看看是不是这个版本的问题,结果之后就装成功了。不过不能说明就一定是VS版本的问题。
    安装VS2015没什么难度,只有一个选项需要自定义,别的选项都可以使用默认值。VS2015的默认安装不包括“C+ +”的编译器,必须手动勾选Visual C+ +,不然会面临后续的CUDA编译错误!!!在这里插入图片描述
    另外这是tensorflow官网上对于VS2015的安装要求:在这里插入图片描述

注意:一定要有Microsoft Visual C++ 2015 Redistributable(大家可以在电脑上找一下!)

  1. CUDA (cuda_10.0.130_411.31_win10
    用来调用gpu的工具,进行高效并行计算;可以在官网上 https://developer.nvidia.com/cuda-downloads 进行下载图中的local就是整个安装包下完整了,不用在安装的过程中再下载了,network则相反,只用下载一个精简的安装包,安装过程中就要先慢慢等待下载。
    !!! 注意事项:
    1、CUDA的版本必须与tensorflow版本一致!!! 具体的版本对应见图(注意:这只是当时的图,现在各版本tensorflow与cuda似乎都向下兼容。比如我的tensorflow就是1.12+cuda10。具体的可以去)
    以及CUDA对显卡驱动也有要求在这里插入图片描述
    大家可以打开NVIDA控制面板里的系统信息看一下自己的显卡驱动是什么版本。在这里插入图片描述

  2. cudnn(cudnn-10.0-windows10-x64-v7.3.1.20
    cuda的一个补丁,用来加速深度学习的一些运算的
    下载地址:https://developer.nvidia.com/rdp/cudnn-download
    (注意:版本要与cuda版本一致!!!)

btw:这个地方有各个版本的cuda和cudnn,如果官网上下载不下来(比如我)可以直接在网盘里下载
网址:https://pan.baidu.com/s/1GrzsWpinRiWMJ8lvs4f1LQ
密码:9ygu

  1. TensorFlow(tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl
    终于到最后一步了…可以直接pip安装也可以在 https://pypi.org/project/tensorflow-gpu/#history 上下载之前各个版本的。whl文件下载下来如何安装可以参考这篇文章:
    https://blog.csdn.net/weixin_41592575/article/details/78984585

运行调试

打开pycharm,配置好有tensorflow的python环境。创建一个test.py文件,输入

import tensorflow as tf

tf.enable_eager_execution()
print(tf.__version__)
hello = tf.constant("hello tensorflow")
print(hello.numpy())

出来这个结果表明安装成功!恭喜
在这里插入图片描述

错误总结

tensorflow、cuda、cudnn版本一定要一致!
VS版本可能不重要,但是Visual C++ 2015 Redistributable这个一定要有。也可能2017的也可以没试过。
Anaconda的国内镜像源挂了,所以如果之前按照教程改成清华镜像源的使用pip指令下载可能下载不下来。
cuda与cudnn从官网上下载我是下载失败。翻墙也不行。不行就用文中给的网盘。
拿不准的就按照文中给的版本,亲测没有问题。

自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.无mkl支持; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 TI 配置信息: 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 编译: bazel build --config=opt --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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值