栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Tensorflow安装教程

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Tensorflow安装教程

1.首先进行虚拟环境建立:

cmd命令下输入activate激活base环境,输入下面代码,创建虚拟环境:

conda create –n tensorflow python=3.7

2.接着从下面网站查找所对应的tensorflow版本,这里面并不一定包含所有版本信息:

在 Windows 环境中从源代码构建  |  TensorFlow (google.cn)https://tensorflow.google.cn/install/source_windows#tensorflow_2x3.在然后从一下网站找到对应版本安装命令:

tensorflow-gpu · PyPIhttps://pypi.org/project/tensorflow-gpu/#history4.在然后进行换源安装:

国内镜像地址:

阿里云 
http://mirrors.aliyun.com/pypi/simple/

中国科技大学 
https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣(douban) 
http://pypi.douban.com/simple/

清华大学 
https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学 
http://pypi.mirrors.ustc.edu.cn/simple/

下面是用豆瓣安装示例:

pip install tensorflow-gpu==1.13.2 -i https://pypi.douban.com/simple --trusted-host pypi.douban.com

有些版本该镜像网站没有,可以尝试换个镜像网站。

5.如果安装错误,卸载命令为:

pip uninstall tensorflow-gpu

6.检查报错信息,循环尝试别的版本,实在不行装CPU版本,直到安装成功。

7.我的环境CUDA为10.0cudnn版本为7.4.15,python为3.7,tensorflow为1.13.2,用上面方法安装,测试是否成功时报错:

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

于是我去安装低版本的protobuf,安装命令为:

pip install protobuf==3.20.1

安装前可以用conda list查看自己当前版本信息,测试代码为:

激活虚拟环境后输入python,复制下面代码:

import tensorflow as tf 
sess = tf.Session() 
a = tf.constant(2) 
b = tf.constant(2) 
print(sess.run(a+b)) 

输出结果为4,测试成。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/987129.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号