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

After a recent update Keras backend cannot find image_dim_ordering parameter.

Has this been moved in the recent update?

import keras
c:\users\popeye\appdata\local\programs\python\python35\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.

keras.backend.image_dim_ordering()
Traceback (most recent call last):

  File "<ipython-input-2-78c718c47677>", line 1, in <module>
    keras.backend.image_dim_ordering()

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 19
  • Comments: 25

Commits related to this issue

Most upvoted comments

In Keras v2 the method has be renamed to image_data_format. So you coud try:

keras.backend.image_data_format()

Source

Also It seems to work with K.common.image_dim_ordering()

The way I understand it, with the new API: setting: K.set_image_dim_ordering('tf') --> K.set_image_data_format('channels_last') K.set_image_dim_ordering('th') --> K.set_image_data_format('channels_first')

checking: K.image_dim_ordering() == 'tf' --> K.image_data_format() == 'channels_last' K.image_dim_ordering() == 'th' --> K.image_data_format() == 'channels_first'

I’m not very familiar with it so there might be other edge cases.

[Edited: Corrected the order as per @CarMiranda 's comment below]

now use k.set_image_data_format('channels_first') The latest version has replaced the image_dim_ordering to image_data_format.

And the function set_image_data_format() does the same as image_dim_ordering was doing.

( use ‘channels_first’ instead of ‘tf’ )

What keras and TensorFlow versions are you using? I checked with Keras 2.2.4 and TF 1.13.1 and was able to execute keras.backend.image_dim_ordering() successfully. Can you please confirm? Thanks!

The way I understand it, with the new API: setting: K.set_image_dim_ordering('tf') --> K.set_image_data_format('channels_first') K.set_image_dim_ordering('th') --> K.set_image_data_format('channels_last')

checking: K.image_dim_ordering() == 'tf' --> K.image_data_format() == 'channels_first' K.image_dim_ordering() == 'th' --> K.image_data_format() == 'channels_last'

I’m not very familiar with it so there might be other edge cases.

this should read: K.set_image_dim_ordering('tf') --> K.set_image_data_format('channels_last') K.set_image_dim_ordering('th') --> K.set_image_data_format('channels_first') K.image_dim_ordering() == 'tf' --> K.image_data_format() == 'channels_last' K.image_dim_ordering() == 'th' --> K.image_data_format() == 'channels_first' (the other way around)

Did you try import keras before using the image ordering functions.

From my little version-wise research, this attribute disappears in 2.2.4 -> 2.2.5 version change. So in my case everything still works fine with 2.2.4.

Thanks everyone for suggestions to fix it!

Replace K.image_dim_ordering() to K.common.image_dim_ordering()

I am having the same error (AttributeError: module ‘keras.backend’ has no attribute ‘image_dim_ordering’) with version 2.3.1. Why?