问题:

当使用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. VMware的安装和使用

    注:内容系兄弟连Linux教程(百度传课:史上最牛的Linux视频教程)的学习笔记. VMware的安装和使用 1. 虚拟机的安装 这里安装虚拟机VMware10,下载安装程序,双击安装-->为 ...

  2. NOIP 2014 提高组 题解

    NOIP 2014 提高组 题解 No 1. 生活大爆炸版石头剪刀布 http://www.luogu.org/problem/show?pid=1328 这是道大水题,我都在想怎么会有人错了,没算法 ...

  3. git bash命令行使用https协议方式进行克隆和提交到github服务器

    在本地创建一个文件夹来存放远程服务器仓库:如创建一个git8文件夹: 在命令行中,使用git clone https://github.com/serverking/weixin.git进行克隆git ...

  4. NYOJ 71 独木舟上的旅行(贪心)

    独木舟上的旅行 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 进行一次独木舟的旅行活动,独木舟可以在港口租到,并且之间没有区别.一条独木舟最多只能乘坐两个人,且乘客 ...

  5. 准备 macvlan 环境 - 每天5分钟玩转 Docker 容器技术(54)

    除了 overlay,docker 还开发了另一个支持跨主机容器网络的 driver:macvlan. macvlan 本身是 linxu kernel 模块,其功能是允许在同一个物理网卡上配置多个 ...

  6. Android护眼模式功能小记

    最近自己在做一个小说阅读器,看到某阅有护眼模式功能,别人都有,我怎么能没有? 现在这功能已经不稀奇了,很多手机都带有这个功能. 实现起来不难,用一个蒙版遮在界面上面就行. 至于蒙版,可以用Window ...

  7. 统计s="hello alex alex hello haiyan cc haiyan com"中每个单词的个数

    这个题可以有好几种解题方法. 一.索引值获取 s="hello alex alex hello haiyan cc haiyan com" l=s.split() dic={} f ...

  8. Fiddler简介

    官网:http://www.telerik.com/fiddler Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的HTTP通讯,设置断点,查看所有的" ...

  9. SQL中多条件查询括号的用途

    界面: 代码 0 posted @ 2009-12-15 13:28 唔愛吃蘋果 阅读(8640) 评论(0)  编辑 收藏

  10. Fedora25和win10双系统安装及使问题汇总

    安装问题汇总 1.U盘引导制作后,开机出现":Assuming driver cache: write through" 解决方案:经过排查后,怀疑是U盘启动制作出了问题,后来查阅 ...