将基于 Theano 的 Keras 模型定义转换为 TensorFlow

Converting Theano-based Keras model definition to TensorFlow

将基于Theano的Keras模型定义转换为TensorFlow时,是否可以更改输入层上input_shape的顺序?

比如下面一层

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

将被替换为

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

注意:我不想使用 dim_ordering='th'

来自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.