Anaconda下载,Anaconda3-5.2.0-Windows-x86_64的版本:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
安装时把PATH环境变量勾上,其他默认。安装这个版本的原因是对应的python是3.6,如果对应的是3.7版本使用conda命令会一直卡在Solving environment
以管理员身份运行cmd,然后配置清华镜像,输入指令:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
在目录 C:\Users<你的用户名> 下就会生成配置文件.condarc,内容如下
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
把第3行删除,再运行
创建运行环境
conda create -n tensorflow-gpu python=3.6
升级pip
python -m pip install --upgrade pip
配置pip镜像源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
下载cudnn7.1.3
https://developer.nvidia.com/rdp/cudnn-archive#a-collapse713-91
官网要注册,下载慢,还经常失败,可以从以下地址下
https://download.csdn.net/download/longma666666/10283519?biz_id=103&utm_term=cudnn%207.1.1&utm_medium=distribute.pc_search_result.none-task-download-2docsobaiduweb~default-1-10283519&spm=1018.2118.3001.4187
安装cudnn,参考
https://blog.csdn.net/weixin_45494025/article/details/100746025
安装TensorFlow GPU版本
pip install tensorflow-gpu==1.6.0 --use-feature=2020-resolver
然后在python里运行import tensorflow as tf应该会报错,
ImportError: Could not find 'cudart64_90.dll
这个错误是因为tensorflow最多支持到cuda9.0,所以把之前的tensorflow卸了,安装一个别人编的支持9.1的版本,可以在下面地址下载
https://download.csdn.net/download/m0_46500149/12366740?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160103759419725222453212%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=160103759419725222453212&biz_id=1&utm_medium=distribute.pc_search_result.none-task-download-2allfirst_rank_ecpm_v3~pc_rank_v2-1-12366740.first_rank_ecpm_v3_pc_rank_v2&utm_term=tensorflow_gpu-1.6.0-cp36&spm=1018.2118.3001.4187
输入命令
pip uninstall tensorflow-gpu
pip install D:\devc++\cuda\tensorflow_gpu-1.6.0-cp36-cp36m-win_amd64.whl
运行测试程序
import tensorflow as tf
# Creates a 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)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
输出结果