Python Keras module ' keras.backend ' has no attribute ' Image_data_format '

Source: Internet
Author: User
Tags keras

Problem:

When you run the sample program MNIST_CNN with Keras, the following error occurs: ' Keras.backend ' has no attribute ' Image_data_format '

Program Path https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py

The Python Conda environment used is the carnd-term1 of the Udacity autopilot course

Fault Program segment:
if ' Channels_first ' :     = X_train.reshape (x_train.shape[0], 1, Img_rows, img_cols)    = X_test.reshape (x_test.shape[0], 1, Img_ Rows, img_cols)    = (1, img_rows, img_cols)else:    = X_train.reshape (x_ Train.shape[0], Img_rows, Img_cols, 1)    = X_test.reshape (x_test.shape[0], img_rows, Img_cols, 1) c17/>= (img_rows, img_cols, 1)

Complete code See https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py

Fault Analysis:

The version of the Keras version in the Conda environment is old in the subroutine, so there is no ' image_data_format ' variable

Workaround:

Here are two ways to choose one

1) If the Keras version is not upgraded

将 K.image_data_format() == ‘channels_first‘Replaced byK.image_dim_ordering() == ‘th‘

2) Upgrade the Keras version to the latest

> Activate Carnd-term1//activating your Conda environment, this environment of mine is called Carnd-term1

(CARND-TERM1) > Conda list//show packages installed in the current environment

(CARND-TERM1) > Pip uninstall Keras//Uninstall old version of Keras, Keras is installed using PIP, so both uninstall and reload use PIP related commands

(CARND-TERM1) > Pip install Keras//Reinstall new version of Keras

(CARND-TERM1) > Conda list//check if the version has been updated

Python Keras module ' keras.backend ' has no attribute ' Image_data_format '

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.