0

I am trying to train a simple regression network on Keras. The input of the network (X_test) are 100 images, and the output another 100. The problem is that I am getting a shape error: I have played with another network architecture, activations,... and the error is still there.

Here I place my code:

M=32

input_layer         = Input(shape=(3, 32, 32), name="input")

sc1_conv1           = Convolution2D(96, 3, 3, activation='relu', init='glorot_uniform', subsample=(2,2), border_mode='valid')(input_layer)

sc1_maxpool1        = MaxPooling2D(pool_size=(2,2))(sc1_conv1)

sc1_fire2_squeeze   = Convolution2D(M, 1, 1, activation='relu', init='glorot_uniform', border_mode='same')(sc1_maxpool1)
sc1_fire2_expand1   = Convolution2D(M*4, 1, 1, activation='relu', init='glorot_uniform', border_mode='same')(sc1_fire2_squeeze)
sc1_fire2_expand2   = Convolution2D(M*4, 3, 3, activation='relu', init='glorot_uniform', border_mode='same')(sc1_fire2_squeeze)
sc1_merge1          = merge(inputs=[sc1_fire2_expand1, sc1_fire2_expand2], mode="concat", concat_axis=1)
sc1_fire2           = Activation("linear")(sc1_merge1)

model               = Model(input=input_layer, output=sc1_fire2)
model.compile(loss='mse', optimizer='rmsprop')
model.fit(X_train, y_train, nb_epoch=10, batch_size=64)

When I run the script, I get the following error:

Exception: Error when checking model target: expected activation_9 to have shape (None, 256, 7, 7) but got array with shape (100, 3, 32, 32)

The X_train and y_train shapes are:

X_train.shape
Out[13]: (100, 3, 32, 32)
y_train.shape
Out[14]: (100, 3, 32, 32)

It is my first time doing regression in Keras and I don't know what I am doing wrong.

Thank you for your time!

sergi2k
  • 5
  • 4

1 Answers1

0

The output shape of your model is (None, 256, 7, 7). That should match with the shape of y_train. To get the shape (None, 3, 32, 32), you'd need to change your architecture, possibly by adding upsampling layers. See https://blog.keras.io/building-autoencoders-in-keras.html for example.

Mikael Rousson
  • 2,247
  • 1
  • 15
  • 16
  • You are right, the solution was changing my architecture using upsample and reshape layers to match the shape of y_train. :) – sergi2k Sep 07 '16 at 13:43