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的标 ...
随机推荐
- n以内质数占的比例
2 ->0.5 10 ->0.4 100-> 0.25 1000->0.168 10000->0.1229 100000->0.09592 1000000-> ...
- 阿里云ECS主机自定义进程监控
由于业务的关系我们用的是阿里云的ECS主机,需要对业务进程需要监控,查看后发现阿里云提供自定义监控SDK,这有助于我们定制化的根据自身业务来做监控,下面我就根据业务需求来介绍一个简单的自定义监控配置 ...
- geotrellis使用(三十)使用geotrellis读取PostGIS空间数据
前言 最近事情很多,各种你想不到的事情--such as singing and dancing--再加上最近又研究docker上瘾,所以geotrellis看上去似乎没有关注,其实我一直在脑中思考着 ...
- X-NUCA 2017 web专题赛训练题 阳光总在风雨后和default wp
0X0.前言 X-NUCA 2017来了,想起2016 web专题赛,题目都打不开,希望这次主办方能够搞好点吧!还没开赛,依照惯例会有赛前指导,放一些训练题让CTFer们好感受一下题目. 题目有一大 ...
- JavaScript基础知识(一)
一.JavaScript基础 1.JavaScript用法: HTML 中的脚本必须位于 <script> 与 </script> 标签之间. 脚本可被放置在 HTML 页面的 ...
- MySQL连接问题【mysql_connect和mysql_pconnect区别】
--MySQL连接问题[mysql_connect和mysql_pconnect区别] -------------------------------------------------------- ...
- SQL连接、合并、子查询
连接:连接分为内连接.外连接.交叉连接 内连接和外连接都是在笛卡尔积的基础做一些修改. 合并查询:把两个相似的结果可以用union联合起来. mysql> select id,time from ...
- 常见C++面试题(三)
strcpy和memcpy有什么区别?strcpy是如何设计的,memcpy呢? strcpy提供了字符串的复制.即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制字符串的结束 ...
- Mac实用操作技巧(六)
Night Shift,保护你夜间的眼睛 之前在Mac上有一款很著名的软件叫f.lux,这款软件会根据Mac的时间和地理位置,来自动切换屏幕亮度,如果进入晚上则调成暖色,白天就切换成普通颜色.现在Ma ...
- 导入import com.sun.image.codec.jpeg.JPEGCodec出错
在Eclipse中处理图片时,需要引入两个包:import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPE ...