问题:

当使用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'的更多相关文章

  1. module 'scipy.misc' has no attribute 'toimage',python

    anaconda环境下: 错误:python 命令行运行出错:module 'scipy.misc' has no attribute 'toimage' 解决:打开Anaconda prompt,输 ...

  2. Python报错module 'scipy.misc' has no attribute 'xxx'

    Python报错module 'scipy.misc' has no attribute 'imresize' 解决办法: 安装Pillow包,命令如下: pip install Pillow 然后重 ...

  3. python 3.7 安装 sklearn keras(tf.keras)

    # 1   sklearn  一般方法 网上有很多教程,不再赘述. 注意顺序是 numpy+mkl     ,然后 scipy的环境,scipy,然后 sklearn # 2 anoconda ana ...

  4. pycharm最新版新建工程没导入本地包问题:module 'selenium.webdriver' has no attribute 'Firefox'

    前言 最新版的pycharm做了很大的改变,新建工程的时候,默认不导入本地的安装包,这就导致很多小伙伴踩坑了... 明明已经pip安装过selenium了,但是却报AttributeError:mod ...

  5. python模块module package

    python模块module   package module package 常用模块 模块与包的区别 模块分为内置模块.第三方模块,自定义模块 程序会先从内置到第三方再到当前工作目录下去找你导入的 ...

  6. ansible报错AttributeError: module 'urllib.request' has no attribute 'HTTPSHandler'

    报错内容: TASK [activemq : extract activemq tarball] *************************************************** ...

  7. 安装socketio出现module 'importlib._bootstrap' has no attribute 'SourceFileLoader' 错误

    安装socketio出现module 'importlib._bootstrap' has no attribute 'SourceFileLoader' 错误 执行: pip install --u ...

  8. AttributeError: module 'scipy.misc' has no attribute 'imread'

    运行python程序报错:AttributeError: module 'scipy.misc' has no attribute 'imread' 报错原因1:scipy版本过高 解决方案:降低sc ...

  9. Requests:Python HTTP Module学习笔记(一)(转)

    Requests:Python HTTP Module学习笔记(一) 在学习用python写爬虫的时候用到了Requests这个Http网络库,这个库简单好用并且功能强大,完全可以代替python的标 ...

随机推荐

  1. Openresty使用Thrift安装步骤

    最新想用Golang与Openresty相互通讯调用,使用RPC协议来实现,后来研究最终选择了Thrift:主要还是FB实现了支持Lua和Go模块,直接编译就可以成功嵌套使用,非常方便:研究了两天最后 ...

  2. ASP.NET WebApi 使用Swagger生成接口文档

    前言 公司一直采用Word文档方式与客户端进行交流.随着时间的推移,接口变的越来越多,文档变得也很繁重.而且一份文档经常由多个开发人员维护,很难保证文档的完整性.而且有时写完代码也忘了去更新文档,为了 ...

  3. python基础===使用switch方法,减少使用if语句

    def jia(x,y): return x+y def jian(x,y): return x-y def cheng(x,y): return x*y def chu(x,y): return x ...

  4. python学习===从一个数中分解出每个数字

    题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数",因为153=1 ...

  5. CSS3 基础(1)——选择器详解

    CSS3选择器详解 一. 属性选择器 在CSS3中,追加了三个属性选择器分别为:[att*=val].[att^=val]和[att$=val],使得属性选择器有了通配符的概念. 选择器 示例 描述 ...

  6. Cox回归模型【生存分析】

    参考:<复杂数据统计方法--基于R的应用> 吴喜之 在生存分析中,研究的主要对象是寿命超过某一时间的概率.还可以描述其他一些事情发生的概率,例如产品的失效.出狱犯人第一次犯罪.失业人员第一 ...

  7. windows 注入 之 SetWindowHookEx

    前面的项目用到hook 还是在半年前,没想到最近有用到了,说实话,在项目组就提出,能用别的办法还是不要用这种,毕竟不太正道(感觉哈). 最近又牵扯到第三方对接的任务,没办法我又回到了HOOK上了.与窗 ...

  8. MySQL数据库— 汇总和分组数据

    一 汇总和分组数据 查询语句 ---> 结果集(多条数据) ---> 聚合函数  ----> 单行记录 1.常用的聚合函数: sum()         数字             ...

  9. 【SSH】---【Struts2、Hibernate5、Spring4】【SSH框架整合笔记 】

    一.为什么要使用接口? 三层体系架构上层调用下层的时候最好使用接口,比如action层调用service的时候,private IUserDAO userDAO;这里将属性定义为接口,调用DAO的时候 ...

  10. MyBatis实现Mysql数据库分库分表操作和总结

    前言 作为一个数据库,作为数据库中的一张表,随着用户的增多随着时间的推移,总有一天,数据量会大到一个难以处理的地步.这时仅仅一张表的数据就已经超过了千万,无论是查询还是修改,对于它的操作都会很耗时,这 ...