title: How to pass multiple values to keras joined model
body: <p>I'm having two pre-trained models. Assume those are model_A and model_B. Here, the model_A is a CNN + LSTM network and model_B is a GCN. </p>
  
  <p>Model_A:</p>
  
  <p><a href="https://i.stack.imgur.com/Ty3KH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ty3KH.png" alt="enter image description here"></a></p>
  
  <p>Model_A requires 1 input as below.
  <code>
  X_in = Input(shape=(None, 150), name='X_in', dtype=int32)</code></p>
  
  <p>Model_B:</p>
  
  <p><a href="https://i.stack.imgur.com/csu4W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/csu4W.png" alt="enter image description here"></a></p>
  
  <p>Model_B requires 3 inputs as below.
  <code>
  X_in = Input(shape=(X_train_B[0].shape[-1], ), name='X_in', dtype=tf.float64)
  A_in = Input(shape=(None,), sparse=True, dtype=tf.float64)
  I_in = Input(shape=(), name='segment_ids_in', dtype=tf.int32)</code></p>
  
  <p>I need to merged these two models by getting the output of the layer before the last layer. Below is how I defined the new model.</p>
  
  <pre><code>model_A = load_model('model_A.h5')
  model_A = Model(inputs=model_A.inputs, outputs=model_A.layers[-2].output)
  
  model_B = load_model('model_B.h5', custom_objects={'GraphConvSkip': GraphConvSkip, 'MinCutPool': MinCutPool,
                                                  'GlobalAvgPool': GlobalAvgPool})
  model_B = Model(inputs=model_B.inputs, outputs=model_B.layers[-2].output) 
  
  def final_model():  
      X_in = Input(shape=(X_train_B[0].shape[-1] ), name='X_in', dtype=tf.float64)
      A_in = Input(shape=(None,), sparse=True, dtype=tf.float64)
      I_in = Input(shape=(), name='segment_ids_in', dtype=tf.int32)
      merged = Concatenate(axis=1)([X_in, A_in, I_in])
  
      concat = concatenate([model_A.output, model_B.output], axis=-1)
      concat = Dense(1, activation='sigmoid')(concat)
  
      model = Model(inputs=[model_A.input, merged], outputs=concat)
      adam = tf.keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
      model.compile(optimizer=adam, loss='binary_crossentropy', metrics=['acc'])
      return model
  
  model = final_model()
  model.fit([X_train_A,[X_train_B, A_train_B, I_]], [y_train_A], verbose=1)
  
  </code></pre>
  
  <p>After I executed this code I got below error.</p>
  
  <pre><code>---------------------------------------------------------------------------
  IndexError                                Traceback (most recent call last)
  &lt;ipython-input-54-8c7e818acc11&gt; in &lt;module&gt;
  ----&gt; 1 model = final_model()
        2 
        3 print('Fitting model')
        4 batches = batch_iterator([A_train_B, X_train_B, y_train_B, X_train_A, y_train_A], batch_size=1, epochs=2)
        5 for b in batches:
  
  &lt;ipython-input-53-5c9278e5efb8&gt; in final_model()
        3     A_in = Input(shape=(None,), sparse=True, dtype=tf.float64)
        4     I_in = Input(shape=(), name='segment_ids_in', dtype=tf.int32)
  ----&gt; 5     merged = Concatenate(axis=1)([X_in, A_in, I_in])
        6 
        7     concat = concatenate([model_A.output, model_B.output], axis=-1)
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
      746           # Build layer if applicable (if the `build` method has been
      747           # overridden).
  --&gt; 748           self._maybe_build(inputs)
      749           cast_inputs = self._maybe_cast_inputs(inputs)
      750 
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
     2114         # operations.
     2115         with tf_utils.maybe_init_scope(self):
  -&gt; 2116           self.build(input_shapes)
     2117       # We must set self.built since user defined build functions are not
     2118       # constrained to set self.built.
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/tf_utils.py in wrapper(instance, input_shape)
      304     if input_shape is not None:
      305       input_shape = convert_shapes(input_shape, to_tuples=True)
  --&gt; 306     output_shape = fn(instance, input_shape)
      307     # Return shapes from `fn` as TensorShapes.
      308     if output_shape is not None:
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/merge.py in build(self, input_shape)
      380     shape_set = set()
      381     for i in range(len(reduced_inputs_shapes)):
  --&gt; 382       del reduced_inputs_shapes[i][self.axis]
      383       shape_set.add(tuple(reduced_inputs_shapes[i]))
      384 
  
  IndexError: list assignment index out of range
  
  
  </code></pre>
  
  <p>Can somebody help me to solve how do I pass these input values to two different models? </p>
  
  <p><strong>----Edit 01----</strong></p>
  
  <p>After modifing the code based on Andrea's suggestion I'm getting the following error. I tried to pass inputs using np.array() as well, but still getting the same error. Can you please check where I did the mistake?</p>
  
  <p>Also, here are the values I'm passing to Model B. Since it is a graph, X_ is an <code>N*d</code> feature vector, A_ is an <code>N*N</code> Adjacency Matrix, I_ is the segment_ids getting by calling to <code>get('XAI')</code>.</p>
  
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-71-22f819a7a9cd&gt; in &lt;module&gt;
       18     return model
       19 
  ---&gt; 20 model = final_model()
       21 print('Fitting model')
       22 batches = batch_iterator([A_train_B, X_train_B, y_train_B, X_train_A, y_train_A], batch_size=1, epochs=2)
  
  &lt;ipython-input-71-22f819a7a9cd&gt; in final_model()
        7 
        8 def final_model():
  ----&gt; 9     concat = Concatenate(-1)([model_A.outputs, model_B.outputs]) # merge outputs
       10     concat = Dense(1, activation='sigmoid')(concat)
       11 
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
      771                     not base_layer_utils.is_in_eager_or_tf_function()):
      772                   with auto_control_deps.AutomaticControlDependencies() as acd:
  --&gt; 773                     outputs = call_fn(cast_inputs, *args, **kwargs)
      774                     # Wrap Tensors in `outputs` in `tf.identity` to avoid
      775                     # circular dependencies.
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/merge.py in call(self, inputs)
      179         return y
      180     else:
  --&gt; 181       return self._merge_function(inputs)
      182 
      183   @tf_utils.shape_type_conversion
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/merge.py in _merge_function(self, inputs)
      402 
      403   def _merge_function(self, inputs):
  --&gt; 404     return K.concatenate(inputs, axis=self.axis)
      405 
      406   @tf_utils.shape_type_conversion
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/backend.py in concatenate(tensors, axis)
     2671   """
     2672   if axis &lt; 0:
  -&gt; 2673     rank = ndim(tensors[0])
     2674     if rank:
     2675       axis %= rank
  
  ~/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/backend.py in ndim(x)
     1200 
     1201   """
  -&gt; 1202   dims = x.shape._dims
     1203   if dims is not None:
     1204     return len(dims)
  
  AttributeError: 'list' object has no attribute 'shape'
  
  
  </code></pre>