1、 Anaconda的版本:Anaconda3-2020.02-Windows-x86_64 安装步骤略.
2、 查看自己电脑的cuda支持的版本。NVIDIA控制面板

如图所示:Cuda驱动版本9.0.176。
cuda版本为:cuda_9.0.176_windows

cudnn版本7.0.5

cuda和cudnn安装请自行解决
百度云盘:
链接:https://pan.baidu.com/s/1Vfgs4iLCjAlU5Y2swwCJmA
提取码:w4ep
3.通过 https://tensorflow.google.cn/install/source#linux
左边菜单可以找到对应的win和mac对应版本
查找tensorflow和cuda的对应版本,我本机的版本对应

gpu选择1.5到1.12 python 3.3到3.6 cuDNN =7 CUDA =9
4.打开Anaconda Navigator

3.1点击 Environments
3.2点击create

3.3

填写nema 选择python版本 点击create。
创建完成后会出现自己新建的environment。
一种方式:命令安装tensorflow_gpu

选择 open Terminal

出现命令窗口

切换国内的镜像(国外下载很慢)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
conda config --set show_channel_urls yes
执行成功后,channels 会出现刚才执行的网址

-
查询可以安装的 gpu版本
anaconda search -t conda tensorflow-gpu
我本机上找到
image.png
执行安装命令:
pip install tensorflow-gpu=1.10.0
等待安装完成。
image.png
直接输入python测试或者PyCharm等开发工具测试,(开发工具设置python.exe)
image.png
测试代码:
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
# 新建一个 graph.
import tensorflow as tf
# 新建一个 graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# 新建session with log_device_placement并设置为True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# 运行这个 op.
print(sess.run(c))

失败的话,大概率是cuda,cudnn版本问题。
网友评论