Error after merging two Deep Learning models VGG16 and ResNet50 I have merged two different models namely VGG16 and ResNet50 and given the outputs of the two models as input to another model. I have checked the Layers graph is correct. Before merging the code was running perfectly fine giving correct outputs. I am getting an error:
&quot;ValueError: Shapes (None, None) and (None, 7, 7, 3) are incompatible&quot; on the line 6 

ValueError                                  
Traceback (most recent call last)  
&lt;ipython-input-36-620554d0106f&gt; in &lt;module&gt;()  

4     epochs = 200,  

5     validation_data = validation_generator,  

----&gt; 6     validation_steps=2 

my code is:
inputs_2 = keras.Input(shape=(224, 224, 3), name=&quot;img&quot;)
vgg = VGG16(input_tensor=inputs_2, weights='imagenet', include_top=False) 
for layer in vgg.layers:
    layer.trainable = False

resnet = ResNet50(input_tensor=inputs_2, weights='imagenet', include_top=False)       
for layer in resnet.layers:
    layer.trainable = False

mergedOutput = Concatenate()([vgg.output, resnet.output])
x = layers.Dense(256, activation=&quot;relu&quot;)(mergedOutput)
prediction = Dense(3, activation='softmax')(x)
model = Model(inputs=vgg.input, outputs=prediction)


model.compile(loss=&quot;categorical_crossentropy&quot;,optimizer='adam',metrics=['accuracy'])

keras.utils.plot_model(model, &quot;mini_resnet.png&quot;, show_shapes=True)  
train_datagen = image.ImageDataGenerator(
rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True,
)

test_dataset = image.ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
TRAIN_PATH,
color_mode = &quot;rgb&quot;,
target_size = (224,224),
batch_size = 32,
class_mode = 'categorical'
)
print(train_generator.class_indices)

validation_generator = test_dataset.flow_from_directory(
VAL_PATH,
color_mode = &quot;rgb&quot;,
target_size = (224,224),
batch_size = 32,
class_mode = 'categorical')

history = model.fit_generator(
train_generator,
steps_per_epoch=8,
epochs = 200,
validation_data = validation_generator,
validation_steps=2
)
The 2D feature map is extended to the output layer and hence throwing errors at the Softmax Layer.
 Add Flatten Or GlobalAveragePool after Concatenate.
mergedOutput = keras.layers.Concatenate()([vgg.output, resnet.output])

mergedOutput = keras.layers.GlobalAveragePooling2D()(mergedOutput)  # This line

x = keras.layers.Dense(256, activation=&quot;relu&quot;)(mergedOutput)