问题:

当使用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 //检查版本是否已经更新

最新文章

  1. 新的一年快开始了,学点新东西吧,从React开始(一)
  2. Query Designer:公式冲突
  3. iOS 设计模式之工厂模式
  4. 安卓ROOT后禁用/隐藏导航栏/虚拟按键
  5. Linux ls -l内容详解
  6. CentOS 7:如何安装防火墙?
  7. yaffs2文件系统
  8. android不自动弹出虚拟键盘
  9. Responsive Table 利用@media
  10. 设计模式之桥接模式(Bridge)--结构模型
  11. printf不同格式表示法
  12. Ubuntu 16.04安装和配置Sublime Text 3
  13. Java 逆变与协变的名词说明
  14. 新增加的HTTP状态码 -- 103
  15. flask学习(一)
  16. Linux 一块网卡配置多个IP的方法
  17. PopupWindow下拉列表
  18. MongoDB With Spark遇到的2个错误,不能初始化和sample重复的key
  19. chrome driver 下载
  20. python学习之参数传递

热门文章

  1. Java编写的日历,输入年月,输出这个月的日期与星期
  2. ABP+AdminLTE+Bootstrap Table权限管理系统第八节--ABP错误机制及AbpSession相关
  3. NYOJ 66 分数拆分
  4. Unicode、UTF-8 和 ISO8859-1到底有什么区别
  5. 关于ftp出现425错误
  6. innodb和myisam存储引擎插入速度
  7. DB2的日志理解难点
  8. webpack教程(四)——css的加载
  9. 搭建 keras + tensorflow
  10. centos下从源码安装openssl