问题描述



在使用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. 3天上手Ascend C编程丨通过Ascend C编程范式实现一个算子实例

    本文分享自华为云社区<3天上手Ascend C编程 | Day2 通过Ascend C编程范式实现一个算子实例>,作者:昇腾CANN . 一.Ascend C编程范式 Ascend C编程 ...

  2. Spring Event 观察者模式, 业务解耦神器

    观察者模式在实际开发过程中是非常常见的一种设计模式. Spring Event的原理就是观察者模式,只不过有Spring的加持,让我们更加方便的使用这一设计模式. 一.什么是观察者模式 概念: 观察者 ...

  3. 深入解析 C++ 中的 ostringstream、istringstream 和 stringstream 用法

    引言: 在 C++ 中,ostringstream.istringstream 和 stringstream 是三个非常有用的字符串流类,它们允许我们以流的方式处理字符串数据.本文将深入探讨这三个类的 ...

  4. C++ typedef用法详解

    typedef的语法描述   在现实生活中,信息的概念可能是长度,数量和面积等.在C语言中,信息被抽象为int.float和 double等基本数据类型.从基本数据类型名称上,不能够看出其所代表的物理 ...

  5. 探索Redis与MySQL的双写问题

    本文已收录至GitHub,推荐阅读 Java随想录 微信公众号:Java随想录 原创不易,注重版权.转载请注明原作者和原文链接 目录 双写一致问题 缓存读写策略 Cache-Aside Pattern ...

  6. 使用LiME收集主机物理内存的内容时发生宕机

    作者 pengdonglin137@163.com 现象 在一台ARM64的Centos7虚拟机里加载 https://github.com/504ensicsLabs/LiME 编译出的内核模块时发 ...

  7. List 切割成小 list 分批处理数据

    使用 Google Guava 库中的方法对 bmList 进行分割. Lists.partition() 方法用于将一个列表按指定大小进行分割,返回一个包含分割后子列表的新列表. 在这个例子中,bm ...

  8. go实现一个切片迭代器

    go实现一个简单的切片迭代器 package main import "fmt" type iterator struct { data []int index int // 索引 ...

  9. MATLAB(Octave)命令记录

    1. struct:结构体数组 aaaa_s.a = 1; aaaa_s.b = {'A','B','C'} aaaa_s.c = [1 2 3 4; 5 6 7 8]; save aaaa_s.tx ...

  10. 喜闻乐见最新的ORM查询BUG,看看有没你关注的

    起因,想测试下查询语句的生成,按以下逻辑代码示例 var query = rep.GetLambdaQuery().Take(100); var join = query.Select(b => ...