If you have been using Keras for some time, then you would probably know the
image_dim_ordering parameter of Keras. Specially, if you switch between
TensorFlow and
Theano backends frequently when using Keras.
When I first started using Keras for image classification, most of my experiments failed because I have set the image_dim_ordering incorrectly. Learning from my mistakes, last year I did a post on
what image_dim_ordering is and why is it important.
|
The keras.json file houses the configuration options for Keras |
In short, image_dim_ordering instructed Keras to properly rearrange the image data structure when passing to the backend:
Both TensorFlow and Theano expects 4D tensors of image data as input. But, while TensorFlow expects its structure/shape to be (samples, rows, cols, channels), Theano expects it to be (samples, channels, rows, cols). So, setting the image_dim_ordering to
'tf' made Keras use the TensorFlow ordering, while setting it to
'th' made it Theano ordering.
At least, that's how it used to work.
But recently, if you have updated to the latest version of Keras, you might have run into issues with the dimension ordering, even if you're sure that you set the image_dim_ordering correctly.
You may have gotten errors like,
ValueError: The shape of the input to "Flatten" is not fully defined (got (0, 7,
50). Make sure to pass a complete "input_shape" or "batch_input_shape" argument
to the first layer in your model.
It may seem to you that Keras has started to ignore your image_dim_ordering setting.
And you're right.