title: keras shapes while UpSampling mismatch
body: <p>I'm trying to run this <a href="https://blog.keras.io/building-autoencoders-in-keras.html" rel="noreferrer">convolutional auto encoder</a> sample but with my own data, so I modified its InputLayer accoridng to my images. However, on the output layer there is a problem with dimensions. I'm sure the problem is with UpSampling, but I'm not sure why is this happening: here goes the code.</p>
  
  <pre><code>N, H, W = X_train.shape
  input_img = Input(shape=(H,W,1))  # adapt this if using `channels_first` image data format
  
  x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
  x = MaxPooling2D((2, 2), padding='same')(x)
  x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
  x = MaxPooling2D((2, 2), padding='same')(x)
  x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
  encoded = MaxPooling2D((2, 2), padding='same')(x)
  
  # at this point the representation is (4, 4, 8) i.e. 128-dimensional
  
  x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
  x = UpSampling2D((2, 2))(x)
  x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
  x = UpSampling2D((2, 2))(x)
  x = Conv2D(16, (3, 3), activation='relu')(x)
  x = UpSampling2D((2, 2))(x)
  decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
  
  autoencoder = Model(input_img, decoded)
  autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
  
  autoencoder.summary()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/9EjUa.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9EjUa.png" alt="model summary for my images of 150x81"></a>
  Then, When I run fit, throws this error:</p>
  
  <pre><code>i+=1
  autoencoder.fit(x_train, x_train,
              epochs=50,
              batch_size=128,
              shuffle=True,
              validation_data=(x_test, x_test),
              callbacks= [TensorBoard(log_dir='/tmp/autoencoder/{}'.format(i))])
  
  ValueError: Error when checking target: expected conv2d_23 to have shape (148, 84, 1) but got array with shape (150, 81, 1)
  </code></pre>
  
  <p>I went back to the tutorial code, and try to see its model's summary, and it shows the following:</p>
  
  <p><a href="https://i.stack.imgur.com/2P0jR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2P0jR.png" alt="model summary for images of 28x28"></a>
  I'm sure there is a problem while reconstructing the output on decoder, But I'm not sure why is it, why does it work for 128x28 images but not for mines of 150x81</p>
  
  <p>I guess I can solve this changing a little my image's dimencions, but I'd like to understand what is happening and how can I avoid it</p>