Search code examples
tensorflowtheanokeras

Converting Theano-based Keras model definition to TensorFlow


When converting Theano-based Keras model definition to TensorFlow, is it enough to change the order of input_shape on the input layer?

For example, the following layer

Convolution2D(32, 3, 3, input_shape=(3, img_width, img_height))

will be replaced as

Convolution2D(32, 3, 3, input_shape=(img_width, img_height, 3))

Note: I don't want to use dim_ordering='th'.


Solution

  • Answer from Francois Chollet:

    I think the question means "what input_shape should I pass to my first layer given that I'm using TensorFlow and that my default setting for dim_ordering is "tf"". The answer is yep, that's how you do it, (img_width, img_height, 3).

    Important to note that if you want to load saved models that were trained with Theano with dim_ordering="th", into a model definition for TF with dim_ordering="tf", you will need to convert the convolution kernels. Keras has utils for that.