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'
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!
I recently updated to the bleeding edge version. It's only there that I have the issue.
Also It seems to work with
K.common.image_dim_ordering()
Did you try import keras
before using the image ordering functions.
Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!
In Keras v2 the method has be renamed to image_data_format
. So you coud try:
keras.backend.image_data_format()
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!
I am having the same error (AttributeError: module 'keras.backend' has no attribute 'image_dim_ordering') with version 2.3.1. Why?
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' )
Hello,
I am using following versions:
keras : 2.3.1
tf : 1.14.0
`45
46 def __init__(self, gamma_init=20, **kwargs):
---> 47 if (K.set_image_data_format('channels_first')== 'tf'):
48 self.axis = 3
49 else:
AttributeError: module 'keras.backend' has no attribute 'image_dim_ordering'`
@nikhilshinde095 I think in your case you need
if K.image_data_format() == 'channels_first':
because you are checking, not setting the image_data_format
@TheHugeManatee And what about the old K.set_image_dim_ordering('th')
, if we only have channel_first/last ?
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]
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)
You are right! tf
, i.e. TensorFlow ordering, corresponds to channels_last
.
I edited my original post to avoid confusion for any readers just cursory scrolling through..
I kept running into this problem for several months. Given I am no hack like many others here, I finally figured out it is because of inconsistent version of tensorflow and keras that I have been installing over the years and the major overhaul of tensorflow to ver 2.
No more "AttributeError: module 'keras.backend' has no attribute 'xxxxxxxxx' " for couple days now. Hope this helps. Just a warning, make sure you can afford to uninstall anaconda completely!
Replace K.image_dim_ordering() to K.common.image_dim_ordering()
@kaavyaastalin thanks, this worked for me
I get the following error in colab if I use K.common.image_dim_ordering(),
module 'tensorflow._api.v2.config' has no attribute 'experimental_list_devices'
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]
Thanks, It worked for me
Versions:
Keras - 2.3.1
TensorFlow - 1.14
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!
I'm using 2.3.1, and it's not working,
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!I'm using 2.3.1, and it's not working,
Versions:
Keras - 2.3.1
TensorFlow - 1.14
AttributeError: module 'keras.backend' has no attribute 'image_dim_ordering'
in keras 2.3.1
tried solution:-
1.K.image_dim_ordering() == 'tf' --> K.image_data_format() == 'channels_last' not working.
Hey @Salmanvaliyakath
If you don't want to change your current environment. Then do the following changes in losses.py file, resnet.py file and in train_frcnn.py file
In Keras v2 the 'image_dim_ordering' method has been renamed to image_data_format.
So you could try:
K.image_data_format()` instead of K.image_dim_ordering()
if K.image_data_format() == 'th':
This solved my problem.
Most helpful comment
Also It seems to work with
K.common.image_dim_ordering()