AttributeError: module 'tensorflow' has no attribute 'Session'.解决办法
# 定义计算图
tens1 = tf.constant([1,2,3])# 创建一个会话
sess = tf.Session()# 使用这个创建好的会话来得到关心的运算的结果。比如可以调用 sess.run(result)
# 来得到张量result的取值
print(sess.run(tens1))#关闭会话是的本次运行中使用的到的志愿可以被释放
sess.close()
报错:
AttributeError: module 'tensorflow' has no attribute 'Session'
问题产生的原因:是tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.
解决办法:sess = tf.compat.v1.Session()
替换sess = tf.Session()
结果继续报错:
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
解决办法:添加tf.compat.v1.disable_eager_execution()
# 保证sess.run()能够正常运行
tf.compat.v1.disable_eager_execution()# 定义计算图
tens1 = tf.constant([1,2,3])# 创建一个会话
sess = tf.compat.v1.Session()# 使用这个创建好的会话来得到关心的运算的结果。比如可以调用 sess.run(result)
# 来得到张量result的取值
print(sess.run(tens1))#关闭会话是的本次运行中使用的到的志愿可以被释放
sess.close()
运行成功,输出[1 2 3]
AttributeError: module 'tensorflow' has no attribute 'Session'.解决办法相关推荐
- AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘错误解决
AttributeError: module 'tensorflow' has no attribute 'Session'错误解决 根据网上教程安装tensorflow环境时,最后都会有个测试代码用 ...
- tensorflow2.0及以上版本在使用Session模块时报错:AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘ 已解决
tensorflow2.0版本及之后的版本在使用Session模块时报错:AttributeError: module 'tensorflow' has no attribute 'Session' ...
- AttributeError: module 'tensorflow' has no attribute 'Session'错误解决
Ubuntu刚安装好Tensorflow以后运行 import tensorflow as tf tf.Session() 报错AttributeError: module 'tensorflow' ...
- Python异常:AttributeError: module ‘xxxx‘ has no attribute ‘open‘ 解决办法
前言 小编一直在用 Python 做机器学习,项目折腾了这么久,常用的和不常用的组件都安装了一大堆,按理说不能出现少包的问题. 仔细检查了一下代码,果然发现了一个低级问题,引以为戒.分享出来,也希望新 ...
- AttributeError: module 'tensorflow' has no attribute 'Session'
tf.Session()是旧版本的语法,如果要跑,加入下面代码 https://github.com/tensorflow/tensorflow/issues/34658 import tensorf ...
- AttributeError: module 'tensorflow' has no attribute 'random_normal'
执行<TensorFlow实战Google深度学习框架(第2版)>only源代码 CH3 时如下语句报错 batch_size = 8 w1= tf.Variable(tf.random_ ...
- 成功解决AttributeError: module ‘tensorflow‘ has no attribute ‘get_variable‘
成功解决AttributeError: module 'tensorflow' has no attribute 'get_variable' 目录 解决问题 解决思路 解决方法 解决问题 Attri ...
- 成功解决AttributeError: module tensorflow has no attribute placeholder
成功解决AttributeError: module 'tensorflow' has no attribute 'placeholder' 目录 解决问题 解决思路 解决方法 解决问题 Attrib ...
- 成功解决AttributeError: module tensorflow has no attribute random_normal
成功解决AttributeError: module 'tensorflow' has no attribute 'random_normal' 目录 解决问题 解决思路 解决方法 解决问题 Attr ...
最新文章
- 8.QML Qt Quick Controls 2中常用的界面形式——堆叠式界面(StackView)
- c语言中指,浅析C语言中指与数组.doc
- Observe rainy world
- python笔记1-准确掌握列表和元组
- 深入浅出Linux设备驱动编程--复杂设备驱动
- Struts2.3.1.2安装
- Android仿58同城Loading View
- 小米笔记本pro黑苹果原厂intel蓝牙亲测可用!!
- [速记] 网络安全复习——选择题汇总
- 计算机系统文件命名规则,Windows10系统怎样自定义副本文件默认命名规则
- KK集团5年估值200亿,新零售还好做吗?
- 青少年软件编程(Python)等级考试试卷一级(判断题)2021-9
- 问题服务器防火墙的选择
- 用 UrlSchemes 实现调用应用并传参
- [iOS]ARC下循环引用的问题
- 计算机如何添加新用户,笔记本电脑怎么样快速添加新用户帐号
- Netty空闲检测之写空闲
- 消息中间件MQ及ActiveMQ介绍
- [最小路径覆盖]拦截导弹
- 19年就业形势怎么样