title: ValueError: number of input channels does not match corresponding dimension of filter, 512 != 3
body: <p>It seems <a href="https://stackoverflow.com/questions/45909569/number-of-input-channels-does-not-match-corresponding-dimension-of-filter-in-ker">similar problem</a>, tried its solution but getting </p>
  
  <pre><code>AttributeError: 'Tensor' object has no attribute 'reshape'
  </code></pre>
  
  <p>I am using keras to build a model based on the VGG16, the following code is shown below</p>
  
  <pre><code>if K.image_data_format() == 'channels_first':
      input_shape = (3, 256, 256)
  else:
      input_shape = (256, 256, 3)
  input_image = Input(shape=input_shape)
  base_model = VGG16( weights='imagenet', include_top=False, input_shape=input_shape)
  </code></pre>
  
  <p>This is base model input output</p>
  
  <pre><code>base_model.input
  base_model.output
  &lt;tf.Tensor 'input_14:0' shape=(?, 256, 256, 3) dtype=float32&gt;
  &lt;tf.Tensor 'block5_pool_13/MaxPool:0' shape=(?, 8, 8, 512) dtype=float32&gt;
  </code></pre>
  
  <p>Here we can see, input channels are <code>3</code> but it returns output channels as <code>512</code>.
  (Not sure if it has anything to do with exception thrown.)
  As far as I understand, it is not matching the Channels in the input layer for the CNN. I'm not getting hot to fix it?</p>
  
  <p>Here are the CNN layers:</p>
  
  <pre><code>model = Sequential()
  model.add(Conv2D(32, (5, 5), input_shape=input_shape))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Conv2D(32, (3, 3)))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Conv2D(64, (3, 3)))
  model.add(Activation('relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Flatten())
  model.add(Dense(64))
  model.add(Activation('relu'))
  model.add(Dropout(0.5))
  model.add(Dense(3, activation='softmax'))
  #model.add(Activation('softmax'))
  model = Model(inputs=base_model.input, outputs=model(base_model.output))
  model.compile(loss='categorical_crossentropy',
                optimizer='rmsprop',
                metrics=['accuracy'])
  </code></pre>
  
  <p>The <code>Model()</code> method is throwing below error:</p>
  
  <pre><code>ValueError: number of input channels does not match corresponding dimension of filter, 512 != 3
  
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-66-bace1b0f7f30&gt; in &lt;module&gt;()
       23 model.add(Dense(3, activation='softmax'))
       24 #model.add(Activation('softmax'))
  ---&gt; 25 model = Model(inputs=base_model.input, outputs=model(base_model.output))
       26 model.compile(loss='categorical_crossentropy',
       27               optimizer='rmsprop',
  
  /usr/local/lib/python3.6/dist-packages/keras/engine/topology.py in __call__(self, inputs, **kwargs)
      617 
      618             # Actually call the layer, collecting output(s), mask(s), and shape(s).
  --&gt; 619             output = self.call(inputs, **kwargs)
      620             output_mask = self.compute_mask(inputs, previous_mask)
      621 
  
  /usr/local/lib/python3.6/dist-packages/keras/models.py in call(self, inputs, mask)
      577         if not self.built:
      578             self.build()
  --&gt; 579         return self.model.call(inputs, mask)
      580 
      581     def build(self, input_shape=None):
  
  /usr/local/lib/python3.6/dist-packages/keras/engine/topology.py in call(self, inputs, mask)
     2083             return self._output_tensor_cache[cache_key]
     2084         else:
  -&gt; 2085             output_tensors, _, _ = self.run_internal_graph(inputs, masks)
     2086             return output_tensors
     2087 
  
  /usr/local/lib/python3.6/dist-packages/keras/engine/topology.py in run_internal_graph(self, inputs, masks)
     2233                                 if 'mask' not in kwargs:
     2234                                     kwargs['mask'] = computed_mask
  -&gt; 2235                             output_tensors = _to_list(layer.call(computed_tensor, **kwargs))
     2236                             output_masks = layer.compute_mask(computed_tensor,
     2237                                                               computed_mask)
  
  /usr/local/lib/python3.6/dist-packages/keras/layers/convolutional.py in call(self, inputs)
      166                 padding=self.padding,
      167                 data_format=self.data_format,
  --&gt; 168                 dilation_rate=self.dilation_rate)
      169         if self.rank == 3:
      170             outputs = K.conv3d(
  
  /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in conv2d(x, kernel, strides, padding, data_format, dilation_rate)
     3339         strides=strides,
     3340         padding=padding,
  -&gt; 3341         data_format=tf_data_format)
     3342 
     3343     if data_format == 'channels_first' and tf_data_format == 'NHWC':
  
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_ops.py in convolution(input, filter, padding, strides, dilation_rate, name, data_format)
      779         dilation_rate=dilation_rate,
      780         name=name,
  --&gt; 781         data_format=data_format)
      782     return op(input, filter)
      783 
  
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_ops.py in __init__(self, input_shape, filter_shape, padding, strides, dilation_rate, name, data_format)
      839           "number of input channels does not match corresponding dimension of "
      840           "filter, {} != {}".format(input_channels_dim,
  --&gt; 841                                     filter_shape[num_spatial_dims]))
      842 
      843     strides, dilation_rate = _get_strides_and_dilation_rate(
  
  ValueError: number of input channels does not match corresponding dimension of filter, 512 != 3
  </code></pre>