title: Keras model.predict, InvalidArgumentError, ConcatOp : Dimensions of inputs should match
body: <p>I am using the unit standard network and I can easily train it with keras. But when I want to use model.predict I get the following error massage, InvalidArgument. I have no idea why this is happening.
  I have my input shape when training network as [H,W,3],and the same shape when doing the model.predict</p>
  
  <p>Can anyone help?</p>
  
  <p>I also put my unit network and the way I train.</p>
  
  <pre><code>def UNet(n_input_channels, n_output_channels):
  from keras.layers import Input, Dropout, UpSampling2D, MaxPooling2D, BatchNormalization, Conv2D, Concatenate
  from keras.models import Model
  
  inputs = Input((None, None, n_input_channels))
  conv1 = Conv2D(64, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(inputs)
  conv1 = BatchNormalization()(conv1)
  conv1 = Conv2D(64, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv1)
  conv1 = BatchNormalization()(conv1)
  pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
  conv2 = Conv2D(128, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(pool1)
  conv2 = BatchNormalization()(conv2)
  conv2 = Conv2D(128, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv2)
  conv2 = BatchNormalization()(conv2)
  pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
  conv3 = Conv2D(256, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(pool2)
  conv3 = BatchNormalization()(conv3)
  conv3 = Conv2D(256, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv3)
  conv3 = BatchNormalization()(conv3)
  pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)
  conv4 = Conv2D(512, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(pool3)
  conv4 = BatchNormalization()(conv4)
  conv4 = Conv2D(512, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv4)
  conv4 = BatchNormalization()(conv4)
  drop4 = Dropout(0.5)(conv4)
  pool4 = MaxPooling2D(pool_size=(2, 2))(drop4)
  
  conv5 = Conv2D(1024, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(pool4)
  conv5 = BatchNormalization()(conv5)
  conv5 = Conv2D(1024, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv5)
  conv5 = BatchNormalization()(conv5)
  drop5 = Dropout(0.5)(conv5)
  
  up6 = Conv2D(512, 2, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(UpSampling2D(size = (2,2))(drop5))
  merge6 = Concatenate(axis=-1)([conv4,up6])
  conv6 = Conv2D(512, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(merge6)
  conv6 = BatchNormalization()(conv6)
  conv6 = Conv2D(512, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv6)
  conv6 = BatchNormalization()(conv6)
  
  up7 = Conv2D(256, 2, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(UpSampling2D(size = (2,2))(conv6))
  merge7 = Concatenate(axis=-1)([conv3,up7])
  conv7 = Conv2D(256, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(merge7)
  conv7 = BatchNormalization()(conv7)
  conv7 = Conv2D(256, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv7)
  conv7 = BatchNormalization()(conv7)
  
  up8 = Conv2D(128, 2, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(UpSampling2D(size = (2,2))(conv7))
  merge8 = Concatenate(axis=-1)([conv2,up8])
  conv8 = Conv2D(128, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(merge8)
  conv8 = BatchNormalization()(conv8)
  conv8 = Conv2D(128, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv8)
  conv8 = BatchNormalization()(conv8)
  
  up9 = Conv2D(64, 2, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(UpSampling2D(size = (2,2))(conv8))
  merge9 = Concatenate(axis=-1)([conv1,up9])
  conv9 = Conv2D(64, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(merge9)
  conv9 = BatchNormalization()(conv9)
  conv9 = Conv2D(64, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv9)
  conv9 = BatchNormalization()(conv9)
  conv9 = Conv2D(2, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv9)
  conv9 = BatchNormalization()(conv9)
  conv10 = Conv2D(n_output_channels, 1, activation = 'softmax')(conv9)
  
  return Model(inputs = inputs, outputs = conv10)
  </code></pre>
  
  <p>and do the training as:</p>
  
  <pre><code>model_unet = UNet(n_input_channels=3, n_output_channels=3)
  model_unet.compile(optimizer='adam', loss=dice_coef_loss, metrics=[dice_coef])
  history_unet = model_unet.fit(x_train, y_train, batch_size=batchsize, epochs=epochs, 
                      verbose=1, shuffle=True, 
                      validation_data=(x_validation, y_validation))
  </code></pre>
  
  <p>and the model.predict</p>
  
  <pre><code>predictions = model.predict(sample_images, batch_size=4)
  
  InvalidArgumentError
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell)
     2115             magic_arg_s = self.var_expand(line, stack_depth)
     2116             with self.builtin_trap:
  -&gt; 2117                 result = fn(magic_arg_s, cell)
     2118             return result
     2119 
  
  &lt;decorator-gen-60&gt; in time(self, line, cell, local_ns)
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/IPython/core/magic.pyc in &lt;lambda&gt;(f, *a, **k)
      186     # but it's overkill for just that one bit of state.
      187     def magic_deco(arg):
  --&gt; 188         call = lambda f, *a, **k: f(*a, **k)
      189 
      190         if callable(arg):
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/IPython/core/magics/execution.pyc in time(self, line, cell, local_ns)
     1191         else:
     1192             st = clock2()
  -&gt; 1193             exec(code, glob, local_ns)
     1194             end = clock2()
     1195             out = None
  
  &lt;timed exec&gt; in &lt;module&gt;()
  
  &lt;ipython-input-39-6b97b7df800f&gt; in predict(model, num_samples, indices)
       10     sample_masks = masks[samples_ind, :142, :92]
       11     print samplep_images.shape
  ---&gt; 12     predictions = model.predict(sample_images, batch_size=4)
       13     toc = time.time()
       14     print('Time per image = {:.4f} sec'.format((toc-tic) / num_samples))
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/keras/engine/training.pyc in predict(self, x, batch_size, verbose, steps)
     1167                                             batch_size=batch_size,
     1168                                             verbose=verbose,
  -&gt; 1169                                             steps=steps)
     1170 
     1171     def train_on_batch(self, x, y,
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/keras/engine/training_arrays.pyc in predict_loop(model, f, ins, batch_size, verbose, steps)
      292                 ins_batch[i] = ins_batch[i].toarray()
      293 
  --&gt; 294             batch_outs = f(ins_batch)
      295             batch_outs = to_list(batch_outs)
      296             if batch_index == 0:
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.pyc in __call__(self, inputs)
     2713                 return self._legacy_call(inputs)
     2714 
  -&gt; 2715             return self._call(inputs)
     2716         else:
     2717             if py_any(is_tensor(x) for x in inputs):
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.pyc in _call(self, inputs)
     2673             fetched = self._callable_fn(*array_vals, run_metadata=self.run_metadata)
     2674         else:
  -&gt; 2675             fetched = self._callable_fn(*array_vals)
     2676         return fetched[:len(self.outputs)]
     2677 
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in __call__(self, *args, **kwargs)
     1380           ret = tf_session.TF_SessionRunCallable(
     1381               self._session._session, self._handle, args, status,
  -&gt; 1382               run_metadata_ptr)
     1383         if run_metadata:
     1384           proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
  
  /work/banafsheh.beheshtipour/virenv/local/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.pyc in __exit__(self, type_arg, value_arg, traceback_arg)
      517             None, None,
      518             compat.as_text(c_api.TF_Message(self.status.status)),
  --&gt; 519             c_api.TF_GetCode(self.status.status))
      520     # Delete the underlying status object from memory otherwise it stays alive
      521     # as there is a reference to status from this from the traceback due to
  
  InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [1,512,17,11] vs. shape[1] = [1,512,16,10]
       [[Node: concatenate_1/concat = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32, _device="/job:localhost/replica:0/task:0/device:GPU:0"](batch_normalization_8/cond/Merge, conv2d_11/Relu, concatenate_1/concat-2-LayoutOptimizer)]]
  </code></pre>