问题描述



在使用tensorflow2.0时,遇到了这个问题:

AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

这个报错的意思是:tensorflow模块没有get_default_graph属性

错误原因

这是由于Keras API(https://keras.io/)有多个实现,包括原始和参考实现(https://github.com/keras-team/keras),还有各种其他实现,包括tf.keras,它是TensorFlow的一部分。

由于TensorFlow 2默认为急切执行,因此Keras需要进行一些更改才能与之兼容

解决方法

  1. 方法一:

    将参考实现与TensorFlow后端一起使用。但是,此实现尚未更新以支持TensorFlow 2(截至2019年6月)。
  2. 方法二:

    使用TensorFlow的实现,tf.keras。这个适用于TF 2。

    例如你需要使用tf.keras,必须确保使用正确的导入:
from tensorflow import keras
而不是直接使用:import keras

同样,在要使用keras下的其他模块时:

from tensorflow.keras import layers
而不是使用 from keras import layers

希望这些可以帮助到你

解决Tensorflow2.0出现:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'的问题的更多相关文章

  1. AttributeError: module 'tensorflow' has no attribute 'Session'

      版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_33440324/article/ ...

  2. AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'

    Traceback (most recent call last): File "linear_regression_eager_api.py", line 15, in < ...

  3. AttributeError: module 'tensorflow' has no attribute 'sub'

    官方的例子:运行之后出现以下错误 # 进入一个交互式 TensorFlow 会话. import tensorflow as tf sess = tf.InteractiveSession() x = ...

  4. python,keras,tensorflow安装问题 module 'tensorflow' has no attribute 'get_default_graph'

    module ‘tensorflow’ has no attribute ‘get_default_graph’当我使用keras和tensorflow做深度学习的时候,python3.7报了这个错误 ...

  5. [已解决]pycharm报错:AttributeError: module 'pip' has no attribute 'main'

    > 更新pip后,pycharm更新模块报错,经过一番查找,现提供两种解决办法. 报错片段信息如下: AttributeError: module 'pip' has no attribute ...

  6. AttributeError: module 'tensorflow' has no attribute 'set_random_seed'

    anaconda3 python3.7 安装好tensorflow 后出现上面的问题,原因是安装的tensorflow版本是2.0的,所以使用以前的代码tensorflow中的函数不兼容.

  7. python3 ,AttributeError: module 'tensorflow' has no attribute 'merge_summary'

    error:tensorflow有些方法属性被改了, self.summary_writer = tf.train.SummaryWriter(summary_dir)改为:summary.FileW ...

  8. Debug 路漫漫-14:Python: AttributeError: module 'tensorflow' has no attribute 'sub'

    在调试 <Neural Factorization Machines for Sparse Predictive Analytics>论文的源码(https://github.com/he ...

  9. Tensorflow之AttributeError: module 'tensorflow' has no attribute 'mul'

      tf.mul已经在新版本中被移除,请使用 tf.multiply 代替

  10. 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法

    pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...

随机推荐

  1. Mybatis自动生成mapper和实体类

    准备工作:需要俩个jar包: (1)连接数据库的jar包:mysql-connector-java-5.1.16-bin.jar (2)实现需求的插件Generator:mybatis-generat ...

  2. Mysql优化篇-索引优化与查询优化

    1.索引失败案列 如果查询时没有使用索引,查询语句就会扫描表中所有记录,在数据量大的情况下,查询会很慢. (1)全值匹配 (2)最佳左前缀法则 mysql可以为多个字段创建索引,一个索引可以包括16个 ...

  3. OPPO主题组件开发 - 调试与预览

    本篇作为 OPPO主题组件调试与预览 文档的补充,因为它真的很简单而且太老,一些命令已发生变化 1. 调试前准备 1. PC 端下载 adb命令工具 下载 https://adbdownload.co ...

  4. 甲骨文宣布: 也做 PostgreSQL!

    PostgreSQL 在开源数据库世界中一直是一个标志性的存在.经过35年的严格开发,它以其可靠性.强大的功能和性能而自豪.DB-engines 的突出显示,其市场份额的增长证明了其适应性强的数据模型 ...

  5. 洛谷P2433 小学数学 N 合一

    写完了这道题结果脑子断电把浏览器关了......打开一看 没保存 寄 传送门:[深基1-2]小学数学 N 合一 - 洛谷 第一题 第二题 第三题 这几道题没啥好说的,直接输出就彳亍了 cout < ...

  6. 其它——Redis与Mysql双写一致性方案解析

    文章目录 一 前言 二 一致性方案 三 先更新数据库,再更新缓存 四 先删缓存,再更新数据库 五 先更新数据库,再删缓存 一 前言 首先,缓存由于其高并发和高性能的特性,已经在项目中被广泛使用.在读取 ...

  7. hadoop集群搭建及编程实践

    Hadoop集群搭建 前期准备及JDK,hadoop安装 设置主机名和添加主机映射 验证连通性 SSH无密码登录 配置集群/分布式环境 修改workers 修改文件core-site.xml 修改hd ...

  8. SaaS模式相较传统CRM系统有何优势?

    SaaS模式的CRM客户管理系统相较于传统的CRM客户管理系统更加方便灵活,更加符合如今的市场环境.它解决了传统CRM系统投入大.维护难的难题,降低了中小企业导入CRM的门槛.下面详细说说SaaS模式 ...

  9. 谱图论:Laplacian算子及其谱性质

    1 Laplacian 算子 给定无向图\(G=(V, E)\),我们在上一篇博客<谱图论:Laplacian二次型和Markov转移算子>中介绍了其对应的Laplacian二次型: \[ ...

  10. keepalived部署+nginx高可用

    nginx+keepalived搞性能web网络架构实战配置: 环境准备: keepalived+nginx-1: 192.168.1.23 keepalived+nginx-2: 192.168.1 ...