title: Input 0 is incompatible with layer flatten_5: expected min_ndim=3, found ndim=2
body: <p>I am trying to fine-tune VGG16 neural network, here is the code:</p>
  
  <pre><code>vgg16_model = VGG16(weights="imagenet", include_top="false", input_shape=(224,224,3))
  model = Sequential()
  model.add(vgg16_model)
  #add fully connected layer:
  model.add(Flatten())
  model.add(Dense(256, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(3, activation='softmax')) 
  </code></pre>
  
  <p>I am getting this error:  </p>
  
  <blockquote>
    <p>ValueError Traceback (most recent call last)
     in </p>
    
    <p>2 model.add(vgg16_model)</p>
    
    <p>3 #add fully connected layer:</p>
    
    <p>----> 4 model.add(Flatten())</p>
    
    <p>5 model.add(Dense(256, activation='relu'))</p>
    
    <p>6 model.add(Dropout(0.5))</p>
    
    <p>/usr/local/anaconda/lib/python3.6/site-packages/keras/engine/sequential.py in add(self, layer)
    179                 self.inputs = network.get_source_inputs(self.outputs[0])</p>
    
    <p>180         elif self.outputs:</p>
    
    <p>--> 181             output_tensor = layer(self.outputs[0])</p>
    
    <p>182             if isinstance(output_tensor, list):</p>
    
    <p>183                 raise TypeError('All layers in a Sequential model '</p>
    
    <p>/usr/local/anaconda/lib/python3.6/site-packages/keras/engine/base_layer.py in <strong>call</strong>(self, inputs, **kwargs)</p>
    
    <p>412                 # Raise exceptions in case the input is not compatible</p>
    
    <p>413                 # with the input_spec specified in the layer constructor.</p>
    
    <p>--> 414                 self.assert_input_compatibility(inputs)</p>
    
    <p>415 </p>
    
    <p>416                 # Collect input shapes to build layer.</p>
    
    <p>/usr/local/anaconda/lib/python3.6/site-packages/keras/engine/base_layer.py in assert_input_compatibility(self, inputs)</p>
    
    <p>325                                      self.name + ': expected min_ndim=' +</p>
    
    <p>326                                      str(spec.min_ndim) + ', found ndim=' +</p>
    
    <p>--> 327                                      str(K.ndim(x)))</p>
    
    <p>328             # Check dtype.</p>
    
    <p>329             if spec.dtype is not None:</p>
    
    <p>ValueError: Input 0 is incompatible with layer flatten_5: expected min_ndim=3, found ndim=2</p>
  </blockquote>
  
  <p>I tried many suggested solutions but none of them could solve my problem. How can I solve this? </p>