How to use a pre-trained model as part of our model?

189 views
Skip to first unread message

Marcelino Borges

unread,
Feb 27, 2021, 8:57:59 PM2/27/21
to Keras-users
Hi.

I'm trying to build a model, reusing two pre-trained models as parts of it.

Let us suppose that my component model has the following configuration:

model1 = keras.models.Sequential([
        keras.layers.Dense(400, input_shape=(2,bits), activation="relu"),
        keras.layers.Dropout(0.2),
        keras.layers.Flatten(),
        keras.layers.Dense(400, activation="relu"),
        keras.layers.Dropout(0.2),
        keras.layers.Dense(2, activation="softmax")
])

I would like to train two models with this configuration. Let's say, I would have the model1 and model2 at the end of this step.

My idea is to frozen the the layers of these models.

After that, I would like to merge (with a keras.layers.concatenate layer) the outputs of these two models and connect this concatenation to an output layer (keras.layers.Dense(2, activation="softmax")).

As a final step, I would like to train the resulting model (called ensamble_model).

How can I do that?

Best regards.

Yaoshiang Ho

unread,
Feb 27, 2021, 10:54:32 PM2/27/21
to Marcelino Borges, Keras-users
This is really easy to do in Keras. The fine tuning guide should get you there. Key is that models can be treated as layers. 

Y

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/CANpcTFq64Ohr%2Bwttn3jmJ2WYa%2B%3DNey2W0nLaZ2xC9qjyLO3sfg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages