tensorflow安装

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))

在这里插入图片描述

输出结果

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值