keras combine pretrained model

I would do this in following steps:

  1. Define function for building a clean model with the same architecture:

    def build_base():
        input = Input(shape=(200,))
        dnn = Dense(400, activation="relu")(input)
        dnn = Dense(400, activation="relu")(dnn)
        output = Dense(5, activation="softmax")(dnn)
        model = keras.models.Model(inputs=input, outputs=output)
        return input, output, model
    
  2. Build two copies of the same model:

    input_1, output_1, model_1 = build_base()
    input_2, output_2, model_2 = build_base()
    
  3. Set weights in both models:

    model_1.set_weights(old_model.get_weights())
    model_2.set_weights(old_model.get_weights())
    
  4. Now do the rest:

    merge_layer = concatenate([input_1, output_2])
    dnn_layer = Dense(200, activation="relu")(merge_layer)
    dnn_layer = Dense(200, activation="relu")(dnn_layer)
    output = Dense(10, activation="sigmoid")(dnn_layer)
    new_model = keras.models.Model(inputs=[input_1, input_2], outputs=output)