Win10+Anaconda3+Python3.6+GeForceGTX1060+CUDA9.0+cuDnn7.0+Tensorflow-GPU1.12+keras+spyder+pycharm

参考资料来源,如有侵权请联系删除:
https://www.cnblogs.com/guoyaohua/p/9265268.html
https://blog.csdn.net/hehedadaq/article/details/79845761
https://blog.csdn.net/u012400305/article/details/84590259
https://www.cnblogs.com/gaofighting/p/9917456.html
https://blog.csdn.net/AAlonso/article/details/81504036
https://keras-cn.readthedocs.io/en/latest/for_beginners/keras_windows/#_1

Win10+Anaconda3+Python3.6+GeForceGTX1060+CUDA9.0+cuDnn7.0+Tensorflow-GPU1.12+keras+spyder+pycharm

第一步:安装Anaconda

  1. 下载和安装
    下载地址:https://www.anaconda.com/download/
    我系统是64位,所以下载 64-Bit Graphical Installer (631 MB),之后就是进行安装了。
    不要勾选**“Add Anaconda to my PATH enviroment variable”,我们后面会手动加入。
  2. 配置Anaconda环境变量
    我们点击左下角搜索栏搜索“环境变量”,点击环境变量,选择“Path”,点击“编辑”,
    将以下三个路径加入,注意这里要换成你自己的安装路径。
    C:\Users\namaste\Anaconda3
    C:\Users\namaste\Anaconda3\Scripts
    C:\Users\namaste\Anaconda3\Library\bin
    然后点击“确定”保存,这回再测试一下,再cmd中输入“conda -V”,能正常显示版本号,证明已经配置好了。

第二步:安装TensorFlow-GPU

打开tensorflow官网:https://www.tensorflow.org/install/install_windows#installing_with_anaconda

  1. 创建conda环境
    通过调用下列命令,创建一个名为“tensorflow”的conda环境:
    conda create -n tf-gpu pip python=3.6
  2. 激活环境
    通过以下命令激活conda环境:
    activate tensorflow
    这样就进入了刚创建的“tensorflow”环境。
  3. 安装tensorflow-gpu
    方法1(不推荐):直接安装tensorflow(tf):
    安装GPU版本的tensorflow需要输入以下命令:
    pip install --ignore-installed --upgrade tensorflow-gpu
    如果只需要安装CPU版本的tensorflow则输入以下命令:
    pip install --ignore-installed --upgrade tensorflow
    方法2:通过清华镜像修改的:
    pip install --upgrade tensorflow-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple
    这样安装就是 tensorflow1.12.0 。
    方法3:下载安装包安装
    打开链接https://pypi.org/project/tensorflow-gpu/1.12.0/#files
    下载选定的文件tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl (80.0 MB)
    然后进入到下载目录,pip install tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl
    推荐使用离线安装。
    注意:务必注意一点,在安装完tensroflow后,由于我们是新创建的conda环境,该环境中基本上是空的,有很多包和IDE并没有安装进来,例如“Ipython”,“spyder”。此时如果我们在该环境下打开spyder/Ipyton/jupyter notebook等,会发现其实IDE使用的kernel并不是新建立的这个环境的kernel,而是“base”这个环境的,而“base”环境中我们并没有安装tensorflow,所以一定无法import。这也就是为什么有很多人在安装好tensorflow后仍然在IDE里无法正常使用的原因了。
  4. 安装Anaconda基础包
    通过以下命令安装Anaconda基础包
    conda install anaconda
    这回,我们测试一下是否能import tensorflow
    程序报错,这是由于我们虽然安装好了tensorflow-gpu,但是还需要安装CUDA Toolkit 和 cuDNN。

第三步:安装CUDA Toolkit + cuDNN

  1. 查看需要安装的CUDA+cuDNN版本
    注意,tensorflow是在持续更新的,具体安装的CUDA和cuDNN版本需要去官网查看,要与最新版本的tensorflow匹配。
    方法1:点击查看最新tensorflow支持的CUDA版本:
    https://www.tensorflow.org/install/install_windows#requirements_to_run_tensorflow_with_gpu_support
    tensorflow1.12.0版本支持的是 CUDA® Toolkit 9.0 + cuDNN v7.0,一定要跟着tensorflow 官网的提示来。
    方法2:安装完之后我们需要知道CUDA和CUDNN的版本需要是什么版本
    到C:\Users\namaste\Anaconda3\envs\tf-gpu\Lib\site-packages\tensorflow\python\platform\build_info.py这个文件,
    可以看到使用的CUDA 9.0和cuDNN 7:亲测貌似没有?
  2. 下载CUDA + cuDNN
    在这个网址查找CUDA已发布版本:https://developer.nvidia.com/cuda-toolkit-archive
    我们开始下载cuDnn 7.0,需要注意的是,下载cuDNN需要在nvidia上注册账号,使用邮箱注册就可以,免费的。登陆账号后才能下载。
    cuDNN历史版本在该网址下载:https://developer.nvidia.com/rdp/cudnn-archive。
  3. 卸载原装NVIDIA显卡驱动
  4. 安装cuda cudnn
    遇到了如下问题:The graphics driver could not find compatible graphics hardware。
    这个问题的主要原因是你本机的显卡驱动版本比CUDA8.0中自带的驱动版本高(实际上,不论CUDA装的哪个版本,只要本机驱动比CUDA自带驱动版本高,都可能出现这个问题)。
    解决办法:
    直接点击继续—>同意并继续—>精简安装,直到完成。
    在dos窗口中输入nvcc -V,如果输出是cuda版本信息,则说明安装成功。
    解压cudnn,将这三个文件夹bin、include、lib复制到安装CUDA9.0的路径覆盖原有的文件。
    本机的安装路径为:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0。
    添加环境变量:
    将下面四个路径加入到环境变量中,注意要换成自己的安装路径。
    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64
    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\libnvvp
    到此,全部的安装步骤都已经完成,这回我们测试一下。

这时,在命令行activate tf-gpu
python
import tensorflow as tf
提示错误:Failed to load the native TensorFlow runtime.
无需理会,因为有很多依赖包尚未安装,直接进入第四步

第四步:进入Anaconda Navigator,在tf-gpu环境,安装spyder

测试:import tensorflow as tf
没报错
继续在Python交互式解释器中输入以下几行代码

import tensorflow as tf

hello = tf.constant(‘Hello,Tensorflow!’)

sess = tf.Session()

这时会等待一段时间,命令行出现以下信息
2019-04-22 14:39:55.433677: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-04-22 14:39:55.845062: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
name: GeForce GTX 1060 major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 4.97GiB
2019-04-22 14:39:55.852792: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2019-04-22 14:42:33.894254: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-04-22 14:42:33.898962: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0
2019-04-22 14:42:33.901545: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N
2019-04-22 14:42:33.906961: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4727 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1)

等全部显示完,继续输入
print(sess.run(hello))
如果窗口中输出是b’Hello,Tensorflow’,则说明已经成功。

查看是否使用GPU
import tensorflow as tf
tf.test.gpu_device_name()
窗口中输出:
2019-04-22 15:03:03.015443: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-04-22 15:03:03.323436: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
name: GeForce GTX 1060 major: 6 minor: 1 memoryClockRate(GHz): 1.6705
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 4.97GiB
2019-04-22 15:03:03.330709: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2019-04-22 15:03:04.187494: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-04-22 15:03:04.191738: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0
2019-04-22 15:03:04.194378: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N
2019-04-22 15:03:04.197919: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 4727 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1)
‘/device:GPU:0’

查看在使用哪个GPU
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
窗口中输出
2019-04-22 15:03:39.948390: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2019-04-22 15:03:39.952954: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-04-22 15:03:39.956907: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0
2019-04-22 15:03:39.959366: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N
2019-04-22 15:03:39.961608: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 4727 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1)
[name: “/device:CPU:0”
device_type: “CPU”
memory_limit: 268435456
locality {
}
incarnation: 12454758823252747417
, name: “/device:GPU:0”
device_type: “GPU”
memory_limit: 4957247897
locality {
bus_id: 1
links {
}
}
incarnation: 8139076033355622927
physical_device_desc: “device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0, compute capability: 6.1”
]

第五步:安装keras

pip install keras -U --pre
测试
import keras
输出:
Using TensorFlow backend.
没有报错,那么Keras就已经成功安装了

Keras中mnist数据集测试 下载Keras开发包
conda install git
cd Users\namaste\Downloads\codes\keras\examples
git clone https://github.com/fchollet/keras.git
cd keras\examples
python mnist_mlp.py
程序无错进行,至此,keras安装完成。

第六步:安装pycharm:

下载pycharm-community-anaconda-2019.1.1
并安装

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值