问题描述



在使用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. 《Linux基础》06. 进程管理 · 服务管理

    @ 目录 1:进程管理 1.1:查看进程 1.1.1:ps 1.1.2:pstree 1.1.3:top 1.2:终止进程 1.2.1:kill 1.2.2:killall 2:服务管理 2.1:运行 ...

  2. 关于初次new springboot项目

    如果是新手初学,然后做springboot项目报各种错,改来改去最终都无法出现successful字样. 请先检查,maven环境是否配好. maven环境决定你下载依赖的速度,以及能否下载成功. m ...

  3. MASA MAUI iOS 文件下载与断点续传

    @ 目录 背景 介绍 方案及代码 1.新建MAUI项目 2.建立NSUrlSession会话连接 3.使用NSUrlSessionDownloadTask 创建下载任务 4.DidWriteData ...

  4. c语言代码练习12

    //计算1/1-1/2+1/3...-1/100的和#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main() { in ...

  5. JS逆向实战23 某市wss URL加密+请求头+ws收发

    声明 本文章中所有内容仅供学习交流,抓包内容.敏感网址.数据接口均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关,若有侵权,请联系我立即删除! 本文首发链接为: http ...

  6. 聊聊JDK19特性之虚拟线程

    1.前言 在读<深入理解JVM虚拟机>这本书前两章的时候整理了JDK从1.0到最新版本发展史,其中记录了JDK这么多年来演进过程中的一些趣闻及引人注目的一些特性,在调研JDK19新增特性的 ...

  7. python系列:argparse详解 外部传参给python的库

    一.argparse简介 argparse 模块是 Python 内置的用于命令项选项与参数解析的模块,argparse 模块可以让人轻松编写用户友好的命令行接口,能够帮助程序员为模型定义参数. ar ...

  8. 软件开发人员 Kubernetes 入门指南|Part 1

    Kubernetes 是一个用于部署和管理容器的编排系统.使用 Kubernetes,用户可以通过自动执行管理任务(例如在跨节点间扩展容器并在容器停止时重新启动任务),在不同环境中可靠地运行容器. K ...

  9. 可视化-vscode使用Plotly,绘制直方图

    Plotly 是一款用来做数据分析和可视化的在线平台,功能非常强大,可以在线绘制很多图形比如条形图.散点图.饼图.直方图等等. 概述: plotly在python中绘图使用分三种:1.plotly.g ...

  10. 每天5分钟复习OpenStack(四) virsh 常用命令

    在上一章节中,我们拉起了第一台虚拟机,但是执行virsh shutdown 关机是无法关机的,需要使用virsh destroy 强制断电的命令来关机.为什么会这样了? 这里我们介绍下 QGA的概念 ...