解决Tensorflow2.0出现:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'的问题
问题描述

在使用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需要进行一些更改才能与之兼容
解决方法
- 方法一:
将参考实现与TensorFlow后端一起使用。但是,此实现尚未更新以支持TensorFlow 2(截至2019年6月)。 - 方法二:
使用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'的问题的更多相关文章
- AttributeError: module 'tensorflow' has no attribute 'Session'
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_33440324/article/ ...
- AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'
Traceback (most recent call last): File "linear_regression_eager_api.py", line 15, in < ...
- AttributeError: module 'tensorflow' has no attribute 'sub'
官方的例子:运行之后出现以下错误 # 进入一个交互式 TensorFlow 会话. import tensorflow as tf sess = tf.InteractiveSession() x = ...
- python,keras,tensorflow安装问题 module 'tensorflow' has no attribute 'get_default_graph'
module ‘tensorflow’ has no attribute ‘get_default_graph’当我使用keras和tensorflow做深度学习的时候,python3.7报了这个错误 ...
- [已解决]pycharm报错:AttributeError: module 'pip' has no attribute 'main'
> 更新pip后,pycharm更新模块报错,经过一番查找,现提供两种解决办法. 报错片段信息如下: AttributeError: module 'pip' has no attribute ...
- AttributeError: module 'tensorflow' has no attribute 'set_random_seed'
anaconda3 python3.7 安装好tensorflow 后出现上面的问题,原因是安装的tensorflow版本是2.0的,所以使用以前的代码tensorflow中的函数不兼容.
- python3 ,AttributeError: module 'tensorflow' has no attribute 'merge_summary'
error:tensorflow有些方法属性被改了, self.summary_writer = tf.train.SummaryWriter(summary_dir)改为:summary.FileW ...
- Debug 路漫漫-14:Python: AttributeError: module 'tensorflow' has no attribute 'sub'
在调试 <Neural Factorization Machines for Sparse Predictive Analytics>论文的源码(https://github.com/he ...
- Tensorflow之AttributeError: module 'tensorflow' has no attribute 'mul'
tf.mul已经在新版本中被移除,请使用 tf.multiply 代替
- 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法
pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...
随机推荐
- COF框架集成mongodb驱动
今天打算在我的COF框架中集成mongodb驱动,这实在是简单的工作,因为基本上只是对pymongo的封装 数据库的集成大同小异,要考虑的点无非是以下几点: 1.命名 2.连接创建 3.连接池管理 4 ...
- Xshell7 / Xftp7 永久免费,官网直连下载地址
主要目的是让大家随时随地从官网下载Xshell和Xftp免费版(个人/家庭/学校免费) 最新变动:官方目前仅提供最新版以及上一个版本的软件下载!其他版本不提供下载 免费版5版本(最后一个版本,无任何限 ...
- 关于Teamcenter RAC开发如何查看Soa调用情况,已经查看反编译源码
- Oracle查询--增加--删除--修改主键
对Oracle表主键的操作,有四类:查询,增加,修改,删除 1.查询主键 /*查询某个表中存在的约束*/ select * from user_constraints where table_name ...
- 其它-Supervisor的使用
文章目录 Supervisor 的使用 一 Supervisor介绍 二 安装 2.1 安装方式 2.2 验证 2.3 配置 2.4 配置详情(了解) 2.5 启动.停止.重启 三 program 配 ...
- 通过资源名称得到资源id
demo地址 主要应用类 package com.example.activitylibrary; import android.app.Activity; import android.os.Bun ...
- FFMPEG+SDL简单视频播放器——视频快进
之前写过一篇关于视频播放器的文章.播放器只简单实现了视频播放的功能,在此功能的基础上,给它加上一个视频快进的功能. 实现 添加参数 // video play control bool do_seek ...
- MPL协议原文
MPL协议原文 原文参考链接 中文翻译有一个,但是只翻译了两条 原文 Mozilla Public License Version 2.0 1. Definitions 1.1. "Cont ...
- CentOS7 Ceph分布式集群部署
CentOS 7 下安装Ceph-nautilus 本问主要记录在CentOS 7下如何安装Ceph-nautilus,安装过程中遇到的一些问题及解决方法. 1.Ceph实验准备 以下是本次实验所用到 ...
- Kubernetes 迁移节点 Kubelet 数据存储目录
1.概述 默认Kubernetes节点Kubelet数据目录在/var/lib/kubelet,如果在部署前没有做好规划,其实默认就存储在系统盘/分区下了,这可能会引发一些问题: 磁盘空间限制: 系统 ...