title: Fine-tuning VGG, got:Negative dimension size caused by subtracting 2 from 1
body: <p>I'm fine-tuning a VGG19 model for the MNIST task.
  The images in MNIST is (28,28,1),which is one channel.
  But the VGG wants to input to be (?,?,3), which is three channels.</p>
  
  <p>So,my way is to add one more Conv2D layer before all the VGG layers to change the (28,28,1) data to (28,28,3), here's my code:</p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>inputs = Input(shape=(28,28,1))
  x = Conv2D(3,kernel_size=(1,1),activation='relu')(inputs)
  print(x.shape)
  # out: (?, 28, 28, 3)
  </code></pre>
  
  <p>Now my input shape is correct(I think).</p>
  
  <p>Here's my whole model:
      # change the input shape:
      inputs = Input(shape=(28,28,1))
      x = Conv2D(3,kernel_size=(1,1),activation='relu')(inputs)</p>
  
  <pre class="lang-python prettyprint-override"><code># add POOL and FC layers:
  x = base_model(x)
  x = GlobalMaxPooling2D()(x)
  x = Dense(1024,activation='relu')(x)
  predictions = Dense(10,activation='softmax')(x)
  
  model = Model(inputs=inputs, outputs=predictions)
  
  # freeze the base_model:
  for layer in base_model.layers:
      layer.trainable = False
  
  model.compile(optimizer='adam',loss='categorical_crossentropy',metric=['accuracy'])
  </code></pre>
  
  <p>and I got:</p>
  
  <pre class="lang-python prettyprint-override"><code>InvalidArgumentError: Negative dimension size caused by subtracting 2 from 1 for 'vgg19_10/block5_pool/MaxPool' (op: 'MaxPool') with input shapes: [?,1,1,512].
  </code></pre>
  
  <p>I had searched the problem and one solution is to add</p>
  
  <pre class="lang-python prettyprint-override"><code>from keras import backend as K
  K.set_image_dim_ordering('th')
  </code></pre>
  
  <p>but it didn't work for me.</p>
  
  <p>What's wrong with my code?</p>