I'm testing the convolutional autoencoder from the author of Keras just here : https://blog.keras.io/building-autoencoders-in-keras.html
But I have this problem :
Exception: Error when checking model target: expected convolution2d_7 to have shape (None, 8, 32, 1) but got array with shape (60000, 1, 28, 28)
I precise, I already setted the field 'border_mode='same'' in the last conv layer. So I really don't know from where it come from.. Here is the summary :
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_1 (InputLayer) (None, 1, 28, 28) 0
____________________________________________________________________________________________________
convolution2d_1 (Convolution2D) (None, 1, 28, 16) 4048 input_1[0][0]
____________________________________________________________________________________________________
maxpooling2d_1 (MaxPooling2D) (None, 1, 14, 16) 0 convolution2d_1[0][0]
______________________________________________________________________________ ______________________
convolution2d_2 (Convolution2D) (None, 1, 14, 8) 1160 maxpooling2d_1[0][0]
____________________________________________________________________________________________________
maxpooling2d_2 (MaxPooling2D) (None, 1, 7, 8) 0 convolution2d_2[0][0]
____________________________________________________________________________________________________
convolution2d_3 (Convolution2D) (None, 1, 7, 8) 584 maxpooling2d_2[0][0]
____________________________________________________________________________________________________
maxpooling2d_3 (MaxPooling2D) (None, 1, 4, 8) 0 convolution2d_3[0][0]
____________________________________________________________________________________________________
convolution2d_4 (Convolution2D) (None, 1, 4, 8) 584 maxpooling2d_3[0][0]
____________________________________________________________________________________________________
upsampling2d_1 (UpSampling2D) (None, 2, 8, 8) 0 convolution2d_4[0][0]
____________________________________________________________________________________________________
convolution2d_5 (Convolution2D) (None, 2, 8, 8) 584 upsampling2d_1[0][0]
____________________________________________________________________________________________________
upsampling2d_2 (UpSampling2D) (None, 4, 16, 8) 0 convolution2d_5[0][0]
____________________________________________________________________________________________________
convolution2d_6 (Convolution2D) (None, 4, 16, 16) 1168 upsampling2d_2[0][0]
____________________________________________________________________________________________________
upsampling2d_3 (UpSampling2D) (None, 8, 32, 16) 0 convolution2d_6[0][0]
______________________________________________________________________________ ______________________
convolution2d_7 (Convolution2D) (None, 8, 32, 1) 145
upsampling2d_3[0][0]
====================================================================================================
Total params: 8273
____________________________________________________________________________________________________
Finally found the answer. I think the creator of the tutorial tested it with 32x32 MNIST images and not 28x28.
Because, when adding to the last conv layer border_mode='same', you get an output shape of (32,32,1) So, to get the good output (28,28,1) you need to add border_mode='valid' to the before last conv layer.
In summary : Correct the dimension ordering to 28x28x1 instead of 1x28x28. Then add border mode same to the last conv layer And finally add border mode valid to the last conv layer.
Hope this will help.