title: ValueError: Negative dimension size caused by subtracting 5 from 4
body: <p>I got this error message when declaring the input layer in Keras.
  I look at some similar questions but none of the solutions helped me.</p>
  
  <p>This is my code: </p>
  
  <pre><code>model = Sequential()
  model.add(Conv2D(32, kernel_size=(5,5), strides = 1, activation="relu", input_shape=(28,28,1)))
  model.add(MaxPooling2D(pool_size=(2, 2), data_format='channels_first'))
  model.add(Conv2D(64, kernel_size=(5,5), strides = 1,  activation="relu"))
  model.add(MaxPooling2D(pool_size=(2, 2), data_format='channels_first'))
  model.add(Conv2D(128, kernel_size=(5,5), strides = 1, activation="relu"))
  model.add(MaxPooling2D(pool_size=(2, 2), data_format='channels_first'))
  model.add(Flatten())
  model.add(Dense(10, activation="softmax"))
  </code></pre>
  
  <p>Full error message:</p>
  
  <pre><code>
  ---------------------------------------------------------------------------
  InvalidArgumentError                      Traceback (most recent call last)
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs, op_def)
     1653   try:
  -&gt; 1654     c_op = pywrap_tf_session.TF_FinishOperation(op_desc)
     1655   except errors.InvalidArgumentError as e:
  
  InvalidArgumentError: Negative dimension size caused by subtracting 5 from 4 for '{{node conv2d_17_1/Conv2D}} = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="VALID", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](max_pooling2d_9_1/Identity, conv2d_17_1/Conv2D/ReadVariableOp)' with input shapes: [?,20,4,32], [5,5,32,128].
  
  During handling of the above exception, another exception occurred:
  
  ValueError                                Traceback (most recent call last)
  14 frames
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs, op_def)
     1655   except errors.InvalidArgumentError as e:
     1656     # Convert to ValueError for backwards compatibility.
  -&gt; 1657     raise ValueError(str(e))
     1658 
     1659   return c_op
  
  ValueError: Negative dimension size caused by subtracting 5 from 4 for '{{node conv2d_17_1/Conv2D}} = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="VALID", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](max_pooling2d_9_1/Identity, conv2d_17_1/Conv2D/ReadVariableOp)' with input shapes: [?,20,4,32], [5,5,32,128].
  </code></pre>