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的标 ...
随机推荐
- 如何快速查看github代码库中第一次commit的记录
发现一个别人推荐的代码库用来学习源码, star星还不少,别人推荐从第一次commit开始阅读,于是试着去找commits的第一次 问题来了,这个代码库commits7855次,点击进入commits ...
- RedHat Enterprise Linu…
RedHat Enterprise Linux 6.4 使用Centos 6 的yum 源问题 2015.04.09 一.问题描述 有时在使用RedHat 系统进行安装某些软件时,会出现如下提示: T ...
- react-router 离开路由前确认
react路由在做离开前确认时,有两种方法 第一种是我们写的是动态路由,可以做一个简单的离开前确认 path: '/association/administration', component: Ad ...
- NYOJ--927--dfs--The partial sum problem
/* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 N ...
- js获取url,截取url参数,截取url后文件名
获取当前: var url = window.location.href; 百度为例: var url=window.location.href; console.info(url); http:// ...
- 史上最全的java随机数生成算法[转载]
package com.zuidaima.core.util; import java.util.Random; public class RandomUtil { public static fin ...
- oracle 基础(上)
sql 语句氛围以下三种类型: dml:Date Manipulation Language 数据操纵语言 DDL:Data Definition Language 数据定义语言 DCL:Data ...
- ASP.NET Core Razor页面 vs MVC
作为.NET Core 2.0发行版的一部分,还有一些ASP.NET的更新.其中之一是添加了一个新的Web框架来创建"页面",而不需要复杂的ASP.NET MVC.新的Razor页 ...
- 关于json数据格式错误
之前我在自己写json数据的时候,一直报错,改了很多没有找到错误,最后发现居然是单引号的问题,webstorm里的json数据格式只能用双引号,不能用单引号
- 第一阶段项目(3body)
<div class="H1"> <div class="top-nav"> < ...