5
votes

I tried to execute some tutorial transfer learning project. But I've got attribute error.

I checked my tensorflow and keras version.

tensorflow : 1.14.0 keras : 2.2.5

and python 3.6.9 version.

the code is here.

if(K.image_dim_ordering() == 'th'):
  input_tensor = Input(shape=(3, 299, 299))

error message here.

AttributeError: module 'keras.backend' has no attribute 'image_dim_ordering'
5

5 Answers

12
votes

keras.backend.common module has image_dim_ordering()

if(K.common.image_dim_ordering() == 'th'):

    input_tensor = Input(shape=(3, 299, 299))
4
votes

Self answer for who has same issue with me. image_dim_ordering change to image_data_format from Keras 2.x. Since change image_dim_ordering to image_data_format.

reference link

4
votes

Replace image_dim_ordering to image_data_format

if(K.image_dim_ordering() == 'th'): 
  input_tensor = Input(shape=(3, 299, 299))

change the above code to

if K.image_data_format() == 'th':
  input_tensor = Input(shape=(3, 299, 299))

Keras Backend utilities

1
votes

You can use the following to change the format to channels_firs:

keras.backend.set_image_data_format('channels_first')
use this to check your format:
 keras.backend.image_data_format()
1
votes

It specifies which dimension ordering convention Keras will follow. To confirm what your keras is using check your Keras configuration file at:

~/.keras/keras.json

In file if contents are

{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}

then make changes to

if K.image_data_format() == 'channels_last':
    input_tensor = Input(shape=(3, 299, 299))

If file contents are

{
    "image_dim_ordering": "tf",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "tensorflow"
}

then make changes to

if(K.image_dim_ordering() == 'th'):
  input_tensor = Input(shape=(3, 299, 299))