title: How to perform deconvolution in Keras/ Theano?
body: <p>I am trying to implement deconvolution  in Keras. My model definition is as follows: </p>
  
  <pre><code>model=Sequential()
  
  
  model.add(Convolution2D(32, 3, 3, border_mode='same',
                          input_shape=X_train.shape[1:]))
  model.add(Activation('relu'))
  model.add(Convolution2D(32, 3, 3, border_mode='same'))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  model.add(Dropout(0.25))
  
  model.add(Convolution2D(64, 3, 3, border_mode='same'))
  model.add(Activation('relu'))
  model.add(Convolution2D(64, 3, 3,border_mode='same'))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  model.add(Dropout(0.25))
  
  model.add(Flatten())
  model.add(Dense(512))
  model.add(Activation('relu'))
  model.add(Dropout(0.5))
  model.add(Dense(nb_classes))
  model.add(Activation('softmax'))
  </code></pre>
  
  <p>I want to perform deconvolution or transposed convolution on the output given by the first convolution layer i.e. <code>convolution2d_1</code>.</p>
  
  <p>Lets say the feature map we have after first convolution layer is <code>X</code> which is of <code>(9, 32, 32, 32)</code> where 9 is the no of images of dimension <code>32x32</code> I have passed through the layer. The weight matrix of the first layer obtained by <code>get_weights()</code> function of Keras. The dimension of weight matrix is <code>(32, 3, 3, 2)</code>. </p>
  
  <p>The code I am using for performing transposed convolution is </p>
  
  <pre><code> conv_out = K.deconv2d(self.x, W, (9,3,32,32), dim_ordering = "th")
   deconv_func = K.function([self.x, K.learning_phase()], conv_out)
   X_deconv = deconv_func([X, 0 ])
  </code></pre>
  
  <p>But getting error:</p>
  
  <pre><code> CorrMM shape inconsistency:
    bottom shape: 9 32 34 34
    weight shape: 3 32 3 3
    top shape: 9 32 32 32 (expected 9 3 32 32)
  </code></pre>
  
  <p>Can anyone please tell me where I am going wrong?</p>