背景
研一现在开始要准备开题,科研项目与图像处理有关。打算用深度学习来试一试。这周先试着搭一下环境。因为是刚开始,所以想着先在自己笔记本上跑一跑试试看。所以就在win10下先试一试吧。参考一些别人的教程。自己搭的时候没想到竟然搭了两天。(走了不少弯路踩了不少坑)。写这篇文章的一个目的也是以后再搭的时候省的自己忘了…
配置及准备工作
计算机配置
- windows 10 64位
- NVIDIA GeForce GTX 960M
所需软件
- Anaconda3(python3.6)
- PyCharm
- VS2015
- CUDA10
- cuDNN7.3
- tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl
下载及安装
- 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/
怎么设置前面的文章应该有提到。
-
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
来进行破解和汉化。 -
VS2015
安装VS这一步必须要在cuda安装之前,否则会导致cuda安装错误!!
按照道理来说只要是高于2015版本的VS都应该可以,我之前电脑上就是VS2017,之前看的别人的文章也是有各种版本的VS。不过因为本人在装的时候老出现问题。索性卸载了2017装了2015看看是不是这个版本的问题,结果之后就装成功了。不过不能说明就一定是VS版本的问题。
安装VS2015没什么难度,只有一个选项需要自定义,别的选项都可以使用默认值。VS2015的默认安装不包括“C+ +”的编译器,必须手动勾选Visual C+ +,不然会面临后续的CUDA编译错误!!!
另外这是tensorflow官网上对于VS2015的安装要求:
注意:一定要有Microsoft Visual C++ 2015 Redistributable(大家可以在电脑上找一下!)
-
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控制面板里的系统信息看一下自己的显卡驱动是什么版本。 -
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
- 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从官网上下载我是下载失败。翻墙也不行。不行就用文中给的网盘。
拿不准的就按照文中给的版本,亲测没有问题。