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 '