Reputation: 13055
When experimenting with a Keras implementation, I did as follows:
from keras import backend as K
K.set_image_dim_ordering('tf')
It generates the following error message. What does it mean? I think set_image_dim_ordering is included in Keras.
File "train.py", line 14, in <module>
K.set_image_dim_ordering('tf')
AttributeError: 'module' object has no attribute 'set_image_dim_ordering'
Upvotes: 3
Views: 14908
Reputation: 185
Keras is Deep Learning framework which can uses from 'TensorFlow' , 'Theano' and 'CNTK' as a backend. Every backend has its own preferences to use the channel ordering
if you are using 'Theano' as a backend, you should set "channels_first order" and after import keras library you can use this line of code:
keras.backend.set_image_data_format('channels_first')
and data shape is as follows : (channel, rows, columns).
Note: channel order in your "data shape" should be equal to channel order in the "backend". for example if you are using Tensorflow as backend, then the input shape of your data should be channel last order(for RGB image: (rows, columns, channel))
Upvotes: 5
Reputation: 2775
To support both new and old versions of Keras, for theano and tensorflow, you can use this:
try:
if K.backend() == 'theano':
K.set_image_data_format('channels_first')
else:
K.set_image_data_format('channels_last')
except AttributeError:
if K._BACKEND == 'theano':
K.set_image_dim_ordering('th')
else:
K.set_image_dim_ordering('tf')
(taken from "https://github.com/Arsey/keras-transfer-learning-for-oxford102/blob/master/util.py")
Upvotes: 0
Reputation: 569
For tensorflow V2.3
import tensorflow.keras.backend as K
# to know the image order
K.image_data_format()
# to set the image order
K.set_image_data_format()
Upvotes: 0
Reputation: 21
In Keras 2.3.1 uses:
from keras as backend as K
K.common.set_image_dim_ordering('th')
Yes. Its working for me for the Keras version 2.3.1
Upvotes: 2
Reputation: 86
What version are you using?
"In the backend, set_image_ordering
and image_ordering
are now set_data_format
and data_format.
"
Upvotes: 0
Reputation: 1
In Keras 2.3.1 uses:
from keras as backend as K
K.common.set_image_dim_ordering('th')
Upvotes: 0
Reputation: 41
Try this :
from keras import backend as K
K.tensorflow_backend.set_image_dim_ordering('th')
Upvotes: 2
Reputation: 5
You might need to do like this:
from keras import backend as K
K.set_image_dim_ordering("th")
Upvotes: -3