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
Links to this issue
Commits related to this issue
- Replaces image_dim_ordering to image_data_format As mentioned in https://github.com/keras-team/keras/issues/12649 — committed to Behery/TCNActionRecognition by Behery 5 years ago
- Uses image_dim_ordering instead of image_data_format To remain compatible with the newer version of Keras As mentioned in https://github.com/keras-team/keras/issues/12649 — committed to Behery/TCNActionRecognition by Behery 5 years ago
- Uses image_data_format Uses image_data_format instead of image_dim_ordering To remain compatible with the newer version of Keras As mentioned in https://github.com/keras-team/keras/issues/12649 — committed to Behery/TCNActionRecognition by Behery 5 years ago
- Uses image_data_format Uses image_data_format instead of image_dim_ordering To remain compatible with the newer version of Keras As mentioned in https://github.com/keras-team/keras/issues/12649 — committed to Behery/TCNActionRecognition by Behery 5 years ago
- scripts/training.py: Use keras.backend.image_data_format() to support newer keras version. If you want to support newer Keras, then according to [keras-team/keras#12649](https://github.com/keras-team... — committed to edowson/keras-complex by edowson 4 years ago
- scripts/training.py: Use keras.backend.image_data_format() to support newer keras version. If you want to support newer Keras, then according to [keras-team/keras#12649](https://github.com/keras-team... — committed to pelavoie/keras-complex by edowson 4 years ago
- update for Keras compatibility for Keras >= 2.0.0 Image_dim_ordering() no longer exists https://github.com/keras-team/keras/issues/12649 — committed to yrrah/keras-frcnn by yrrah 4 years ago
- Update a line in notebook 4 due to a change in Keras version (as documented at https://github.com/keras-team/keras/issues/12649). — committed to FNALLPC/machine-learning-hats by deleted user 3 years ago
- Fix 'keras.backend' has no attribute 'set_image_dim_ordering' https://github.com/keras-team/keras/issues/12649#issuecomment-610247150 — committed to ProjectDetector/Train-VehicleDetection-model by nkpro2000 3 years ago
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!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 kerasbefore 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?