问题描述



在使用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. Win11和Win10怎么禁用驱动程序强制签名? 关闭Windows系统驱动强制签名的技巧?

    前言 什么是驱动程序签名? 驱动程序签名又叫做驱动程序的数字签名,它是由微软的Windows硬件设备质量实验室完成的.硬件开发商将自己的硬件设备和相应的驱动程序交给该实验室,由实验室对其进行测试,测试 ...

  2. Java 配置 HTTP/Socks 代理竟能如此简单

    在网络请求过程中,使用代理是一种常见的需求.代理服务器可以帮助我们隐藏真实的 IP 地址.加速访问速度.访问公司特定内网等等要求.在 Java 中,我们可以通过一些库或框架来实现代理的设置和使用. 但 ...

  3. 《Python魔法大冒险》003 两个神奇的魔法工具

    魔法师:小鱼,要开始编写魔法般的Python程序,我们首先需要两个神奇的工具:Python解释器和代码编辑器. 小鱼:这两个工具是做什么的? 魔法师:你可以把Python解释器看作是一个魔法棒,只要你 ...

  4. 初识Storm之HelloWorld程序源码

    1. 新建一个Maven项目,pom.xml代码如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xs ...

  5. JAVA-Springboot实践项目-用户注册

    Smiling & Weeping ----我本没喜欢的人, 见你的次数多了, 也就有了. 1.创建数据表 1.1.选中数据表: use store 1.2.创建t_user表: 2创建用户实 ...

  6. git + docker + docker-compose + Jenkins+Linux 自动化构建、部署、测试过程

    Jenkins三大概念: Job:即为任务 插件:maven构建项目.git拉取代码.ssh插件 工作空间:任务的存储空间,即为git代码的存储空间 开发者在本地开发,然后提交到 Source Res ...

  7. 查看docker容器使用的cpu和内存

    转载请注明出处: 使用docker ps命令列出正在运行的Docker容器,并获取目标容器的ID或名称. 使用docker stats <容器ID或名称>命令来实时监测指定容器的资源使用情 ...

  8. 整理DB2左补零,右补零的方法

    在项目中经常遇到需要左补零,右补零的情况,在DB2实验环境中展示 1.左补零(1)数字左补零,数字长度不定用right(digits(cast(expression as bigint)),NUM)能 ...

  9. android 中service的简单事例

    源码 public class ServiceDemoActivity extends Activity { private static final String TAG = "Servi ...

  10. ChatGPT 是如何产生心智的?

    一.前言 - ChatGPT真的产生心智了吗? 来自斯坦福大学的最新研究结论,一经发出就造成了学术圈的轰动,"原本认为是人类独有的心智理论(Theory of Mind,ToM),已经出现在 ...