How to pass common inputs to a merged model in Keras I'm attempting to merge a VGG-16 and ResNet-50 through concatenation. I was successful in training and saving the merged model. Here is the code snippet:

from keras import applications
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D
from keras.layers import Concatenate
from keras.models import load_model
# Loading the training data
img_rows=300
img_cols=300
channel = 3
num_classes = 3
batch_size = 10 
nb_epoch = 10
#load the first model ######################################################### 
base_model1 = applications.VGG16(weights='imagenet', include_top=False, input_shape=(img_rows,img_cols,3))
#get the model summary
base_model1.summary()
#addind the top layers
x1 = base_model1.output
x1 = GlobalAveragePooling2D()(x1) #analogous to flatten()
model1 = Model(inputs=base_model1.input, outputs=x1)
model1.summary()
#load the second model ########################################################
base_model2 = applications.ResNet50(weights='imagenet', include_top=False, input_shape=(img_rows,img_cols,3))
#get the model summary
base_model2.summary()
#addind the top layers
x2 = base_model2.output
x2 = GlobalAveragePooling2D()(x2) #analogous to flatten()
model2 = Model(inputs=base_model2.input, outputs=x2)
model2.summary()

'''merge the models'''
mergedOut = Concatenate()([model1.output,model2.output])
#add a new dense layer and softmax
out=Dense(2048, activation='relu')(mergedOut) 
out = Dense(num_classes, activation='softmax', name='predictions')(out)
#create the new model with three branches and one dense layer
model = Model(inputs=[model1.input,model2.input], outputs=out)
model.summary()
###############################################################################
#training the model
hist=model.fit([X_train, X_train], Y_train, batch_size=batch_size, epochs=nb_epoch, 
                     shuffle=True, verbose=1, validation_data=([X_valid, X_valid], Y_valid)) 


However, the inputs to both the models are the same. I would like to use this as a common input to the merged model to avoid passing X_train and X_valid twice during the model.fit. How can I do this?
I found the answer to my question. I need to pass the common input shape to the individual models and concatenate the outputs like this:

input_shape=(img_rows,img_cols,3)
commonInput = Input(input_shape)
out1 = model1(commonInput)    
out2 = model2(commonInput)  
mergedOut = Concatenate()([out1,out1])