For example I have a model with 3 intermediate layers:
Model1 : Input1 --> L1 --> L2 --> L3
,
and want to split it into
Model2 : Input2 --> L1 --> L2
and Model3 : Input3 --> L3
.
It is easy to stack these two to get the first one using functional API. But I'm not sure how to do the opposite thing.
The first split model can be obtained by: Model(Input1, L2.output)
, but the second one is not that easy. What is the simplest way to do this?
Example code:
# the first model
input1 = Input(shape=(784,))
l1 = Dense(64, activation='relu')(inputs)
l2 = Dense(64, activation='relu')(l1)
l3 = Dense(10, activation='softmax')(l2)
model1 = Model(inputs, l3)
I want to build model2
and model3
described above that share weights with model1
while model1 already exists (maybe loaded from disk).
Thanks!