title: ValueError: Exception encountered when calling layer "max_pooling2d_26" (type MaxPooling2D)
body: <p>I have the following code while building a CNN model with Keras. I have added three convolution layers and three pool layers. While compiling the model a value error arises from the pooling layer. I have added the code and error. please help</p>
  <pre><code>model = Sequential()
  model.add(Conv2D(filters = 32, kernel_size = (4,4), input_shape = (28,28,1), activation = 'relu'))
  model.add(MaxPool2D(pool_size = (2,2)))
  
  
  model.add(Conv2D(filters = 64, kernel_size = (4,4), input_shape = (28,28,1), activation = 'relu'))
  model.add(MaxPool2D(pool_size=(2, 2)))
  
  
  model.add(Conv2D(filters = 64, kernel_size = (4,4), input_shape = (28,28,1), activation = 'relu'))
  model.add(MaxPool2D(pool_size = (2,2)))
  
  model.add(Dense(128, activation = 'relu'))
  model.add(Dropout(0.5))
  
  model.add(Dense(10, activation = 'softmax'))
  model.compile(loss = 'categorical_crossentropy', optimizer = 'rmsprop', metrics = ['accuracy'])
  
  
  
  ### Error
  
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-27-52904ec71757&gt; in &lt;module&gt;
       13 model.add(Conv2D(filters = 64, kernel_size = (4,4), input_shape = (28,28,1), activation = 'relu'))
       14 # pool layer
  ---&gt; 15 model.add(MaxPool2D(pool_size = (2,2)))
       16 
       17 # Dense layer
  
  ~\Anaconda3\lib\site-packages\tensorflow\python\training\tracking\base.py in _method_wrapper(self, *args, **kwargs)
      528     self._self_setattr_tracking = False  # pylint: disable=protected-access
      529     try:
  --&gt; 530       result = method(self, *args, **kwargs)
      531     finally:
      532       self._self_setattr_tracking = previous_value  # pylint: disable=protected-access
  
  ~\Anaconda3\lib\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs)
       65     except Exception as e:  # pylint: disable=broad-except
       66       filtered_tb = _process_traceback_frames(e.__traceback__)
  ---&gt; 67       raise e.with_traceback(filtered_tb) from None
       68     finally:
       69       del filtered_tb
  
  ~\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs, op_def)
     1937   except errors.InvalidArgumentError as e:
     1938     # Convert to ValueError for backwards compatibility.
  -&gt; 1939     raise ValueError(e.message)
     1940 
     1941   return c_op
  
  ValueError: Exception encountered when calling layer &quot;max_pooling2d_29&quot; (type MaxPooling2D).
  
  Negative dimension size caused by subtracting 2 from 1 for '{{node max_pooling2d_29/MaxPool}} = MaxPool[T=DT_FLOAT, data_format=&quot;NHWC&quot;, explicit_paddings=[], ksize=[1, 2, 2, 1], padding=&quot;VALID&quot;, strides=[1, 2, 2, 1]](Placeholder)' with input shapes: [?,1,1,64].
  
  Call arguments received:
    • inputs=tf.Tensor(shape=(None, 1, 1, 64), dtype=float32)
  </code></pre>