# How to combine different models in Keras?

I have a pre-trained network, consist of two parts, the feature extraction, and the similarity learning.

The network takes two inputs and predicts the images are same or not.

The feature extraction part was VGGNet 16 with all layers freezed.

I only extracted the feature vectors and learned the similarity network which consists of the two convolutional layers followed by four dense layers.

Note: Removed last layers from the image due to large size.

Now, I want to fine-tune the last convolutional block of VGGNet and want to use two different VGGNet feature extractors for each type of image.

I have loaded the trained model and created a new model which starts from the Merged_feature_map layer:

model = Sequential()
for layer in ft_model.layers[3:]:


Now, the new model will only contain similarity network without the feature extraction part.

I have loaded two VGGNets for each type of image and unfreeze their last convolutional block as:

vgg_left = VGG16(weights="imagenet", include_top=False, input_tensor=Input(shape=(img_width, img_height, channels)))
vgg_left.name = "vgg_left"

vgg_right = VGG16(weights="imagenet", include_top=False, input_tensor=Input(shape=(img_width, img_height, channels)))
vgg_right.name = "vgg_right"


At that moment, I have 3 models and I want to combine them. The output from both VGG networks should be the input of Merged feature map. How to combine them and make them a single model.

bottleneck_features_r = vgg_left(left_input)
bottleneck_features_s = vgg_right(right_input)


It should be like:

You can get the output of your models with model.output or get_layer and combine them with tf.keras.layers.concatenate