Python Keras module 'keras.backend' has no attribute 'image_data_format'
问题:
当使用Keras运行示例程序mnist_cnn时,出现如下错误: 'keras.backend' has no attribute 'image_data_format'
程序路径https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py
使用的python conda环境是udacity自动驾驶课程的carnd-term1
故障程序段:
if K.image_data_format() == 'channels_first':
x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
input_shape = (1, img_rows, img_cols)
else:
x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
input_shape = (img_rows, img_cols, 1)
完整代码见 https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py
故障分析:
conda环境中的Keras版本比例子程序中的版本旧,因此没有'image_data_format'这个变量
解决方法:
以下两种方法,任选其一
1)如果不升级Keras版本
将 K.image_data_format() == 'channels_first' 替换为 K.image_dim_ordering() == 'th'
2)升级Keras版本到最新
> activate carnd-term1 //激活你的conda环境,我的这个环境叫做carnd-term1
(carnd-term1)> conda list //显示当前环境中安装的包
(carnd-term1)> pip uninstall Keras //卸载旧版本的Keras, Keras是使用pip方式安装的,因此卸载和重装都要使用pip相关命令
(carnd-term1)> pip install Keras //重新安装新版本的Keras
(carnd-term1)> conda list //检查版本是否已经更新
Python Keras module 'keras.backend' has no attribute 'image_data_format'的更多相关文章
- module 'scipy.misc' has no attribute 'toimage',python
anaconda环境下: 错误:python 命令行运行出错:module 'scipy.misc' has no attribute 'toimage' 解决:打开Anaconda prompt,输 ...
- Python报错module 'scipy.misc' has no attribute 'xxx'
Python报错module 'scipy.misc' has no attribute 'imresize' 解决办法: 安装Pillow包,命令如下: pip install Pillow 然后重 ...
- python 3.7 安装 sklearn keras(tf.keras)
# 1 sklearn 一般方法 网上有很多教程,不再赘述. 注意顺序是 numpy+mkl ,然后 scipy的环境,scipy,然后 sklearn # 2 anoconda ana ...
- pycharm最新版新建工程没导入本地包问题:module 'selenium.webdriver' has no attribute 'Firefox'
前言 最新版的pycharm做了很大的改变,新建工程的时候,默认不导入本地的安装包,这就导致很多小伙伴踩坑了... 明明已经pip安装过selenium了,但是却报AttributeError:mod ...
- python模块module package
python模块module package module package 常用模块 模块与包的区别 模块分为内置模块.第三方模块,自定义模块 程序会先从内置到第三方再到当前工作目录下去找你导入的 ...
- ansible报错AttributeError: module 'urllib.request' has no attribute 'HTTPSHandler'
报错内容: TASK [activemq : extract activemq tarball] *************************************************** ...
- 安装socketio出现module 'importlib._bootstrap' has no attribute 'SourceFileLoader' 错误
安装socketio出现module 'importlib._bootstrap' has no attribute 'SourceFileLoader' 错误 执行: pip install --u ...
- AttributeError: module 'scipy.misc' has no attribute 'imread'
运行python程序报错:AttributeError: module 'scipy.misc' has no attribute 'imread' 报错原因1:scipy版本过高 解决方案:降低sc ...
- Requests:Python HTTP Module学习笔记(一)(转)
Requests:Python HTTP Module学习笔记(一) 在学习用python写爬虫的时候用到了Requests这个Http网络库,这个库简单好用并且功能强大,完全可以代替python的标 ...
随机推荐
- Spring Boot整合Dubbo使用及开发笔记
一.概述: Spring Dubbo是我开发的一个基于spring-boot和dubbo,目的是使用Spring boot的风格来使用dubbo.(即可以了解Spring boot的启动过程又可以学习 ...
- PythonTip--一马当先--bfs
刚学python,小试牛刀 一马当先 讨论此题 | 解题报告 顶(39) (AC/Submit)Ratio(477|1829)26.08% 踩(1) 描述: 下过象棋的人都知道,马只能走'日'字形(包 ...
- GDB教程
GDB是一个由GNU开源组织发布的.UNIX/LINUX操作系统下的.基于命令行的.功能强大的程序调试工具. GDB中的命令固然很多,但我们只需掌握其中十个左右的命令,就大致可以完成日常的基本的程序调 ...
- Qt词典搜索
Qt词典搜索 采用阿凡达数据-API数据接口及爱词霸API数据接口实现词典搜索功能,实例字符串搜索接口分别为:中文词组采用“词典”,中文单个字采用“中华字典”,英文或其他字符采用“爱词霸”: 对应的A ...
- css3动画2D、3D转换
css3动画的2D.3D转换代码: <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- koa-router源码分析
koa-router源码地址是 koa-router 当前解读版本为7.2.1 关系图 代码结构图 执行流程图 关系对应图 Router方法和属性浅析 methods.forEach 注册注册路由的方 ...
- Entity Framework入门教程:Oracle数据源访问
由于System.Data.OracleClient.dll从.NET Framework4.0之后已被弃用,所以我们无法在.NET Framework高版本中使用.一番搜索之后,发现好多文章提到.N ...
- unity 竖屏不能全屏显示
最近遇到一个问题,硬件显示屏是1080*1920的竖屏,但是导出后打开exe进去并不能全屏 处理办法是1.确认配置都是正确的,简单来说,就是自适应设定,这个网上有很多,就不赘述了. 2.exe启动时需 ...
- [js高手之路]构造函数的基本特性与优缺点
上文,通过基本的对象创建问题了解了构造函数,本文,我们接着上文继续了解构造函数的基本特性,以及优缺点. 每个对象上面都有一个constructor属性( 严格意义上来说,是原型上的,对象是通过查找到原 ...
- 【Maven】项目中没有resources目录
在eclipse中创建maven项目,src/main/只有java没有resources目录 解决办法: 1.项目右键properties 2.Java Build Path 中移除JRE Syst ...