title: Siamese network with third component error
body: <p>I was able to create a siamese network similar to :</p>
  <p><a href="https://github.com/aspamers/siamese/" rel="nofollow noreferrer">https://github.com/aspamers/siamese/</a></p>
  <p>The problem happens if I try to add a third model as an input to the head of my network.
  I will get the following error :</p>
  <pre><code>ValueError: Shape must be rank 2 but is rank 3 for '{{node head/concatenate/concat}} = ConcatV2[N=3, T=DT_FLOAT, Tidx=DT_INT32](simple/Identity, simple_1/Identity, different/Identity, head/concatenate/concat/axis)' with input shapes: [?,?], [?,?], [?,?,1], [].
  </code></pre>
  <p>Here is the code below, one thing I am not comfortable with is the line processed_a = base_model1(input_a) and what it does even after checking the Keras model doc. I understand that if I don't do it I cannot have the desired shape and provide the necessary inputs to the final network.</p>
  <p>Note that if I replace the code with what is comment and just use a pure siamese network it will work ok.
  Any idea what needs to be changed to resolve the above error and what base_model1(input_a) does.</p>
  <pre><code>import numpy as np
  import tensorflow as tf
  from tensorflow.keras import layers
  from tensorflow.python.keras.layers import *
  
  def getModel1(input_shape):
      model_input = Input(shape=input_shape)
      layer = layers.Dense(32, activation='relu')(model_input)
      layer = layers.Flatten()(layer)
      return tf.keras.Model(inputs=model_input, outputs= layer, name=&quot;simple&quot;)
  
  def getModel3(input_shape):
      model_input = Input(shape=input_shape)
      layer = layers.Dense(1, activation='relu')(model_input)
      return tf.keras.Model(inputs=model_input, outputs=layer, name=&quot;different&quot;)
  
  def outputModel(models):
      inputs = []
      for model in models:
          inputs.append(Input(shape=model.output_shape))
      layer = layers.Concatenate()(inputs)
      layer = layers.Dense(1)(layer)
      return tf.keras.Model(inputs=inputs, outputs=layer, name=&quot;head&quot;)
  
  dataset = []
  inputs1 = []
  for i in range(0, 128):
      dataset.append([0.0, 1.0, 2.0])
  train_dataset1 = np.asarray(dataset)
  base_model1 = getModel1(train_dataset1.shape)
  
  dataset3 = [0.0, 1.0, 2.0]
  train_dataset3 = np.asarray(dataset3)
  base_model3 = getModel3(train_dataset3.shape)
  
  
  input_a = Input(shape=base_model1.input_shape)
  input_b = Input(shape=base_model1.input_shape)
  input_c = Input(shape=base_model3.input_shape)
  
  oModel = outputModel([base_model1, base_model1, base_model3])
  #oModel = outputModel([base_model1, base_model1])
  
  processed_a = base_model1(input_a)
  processed_b = base_model1(input_b)
  processed_c = base_model3(input_c)
  
  head = oModel([processed_a, processed_b, processed_c])
  model = tf.keras.Model(inputs=[input_a, input_b, input_c], outputs=head, name=&quot;model&quot;)
  #head = oModel([processed_a, processed_b])
  #model = tf.keras.Model(inputs=[input_a, input_b], outputs=head, name=&quot;model&quot;)
  optimizer = tf.keras.optimizers.RMSprop(0.001)
  model.compile(loss='mse',
                optimizer=optimizer,
                metrics=['mae', 'mse'])
  
  model.predict([np.asarray([train_dataset1]), np.asarray([train_dataset1]), np.asarray([train_dataset3])])
  #model.predict([np.asarray([train_dataset1]), np.asarray([train_dataset1])])
  model.fit([np.asarray([train_dataset1]), np.asarray([train_dataset1]), np.asarray([train_dataset3])], np.asarray([1.0]), epochs=1000, validation_split=0, verbose=0, callbacks=[])
  #model.fit([np.asarray([train_dataset1]), np.asarray([train_dataset1])], np.asarray([1.0]), epochs=1000, validation_split=0, verbose=0, callbacks=[])
  </code></pre>