Search code examples
pythonkeras-layer

python keras Convolution2D layer works not correctly and gets a wrong result


from keras.models import Sequential
from keras.layers import Convolution2D
model = Sequential()
model.add(Convolution2D(64, 3, 3, border_mode='same', input_shape=(3, 256, 256)))

This example says :

now model.output_shape == (None, 64, 256, 256)

however in my console, I got the reult model.output_shape == (None, 3, 256, 64) I believe there must be someone else got the same wrong result, does anyone have solved this problem?


Solution

  • The same link you give says :

    dim_ordering: 'th' or 'tf'. In 'th' mode, the channels dimension (the depth) is at index 1, in 'tf' mode is it at index 3. It defaults to the image_dim_ordering value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be "tf".

    So your input_shape is like theano's and your output looks like your backend is tensorflow. If you want to use it like this, change your convolution2D layer to :

    model.add(Convolution2D(64, 3, 3, border_mode='same', input_shape=(3, 256, 256), dim_ordering='th'))
    

    or change your images so that the input shape is (256,256,3).

    Your question formulation is not really clear, you don't give much information and the display is quite aggressive btw.