Skip to content

Instantly share code, notes, and snippets.

@miguelmartin75
Created March 23, 2017 03:39
Show Gist options
  • Save miguelmartin75/591fc5b03339020d5aca61da1054a0b3 to your computer and use it in GitHub Desktop.
Save miguelmartin75/591fc5b03339020d5aca61da1054a0b3 to your computer and use it in GitHub Desktop.
from keras.utils import plot_model
from keras.models import Model
from keras.layers import Input, Dense, concatenate
def create_inner_model():
input=Input((10,))
d1 = Dense(128)(input)
d2 = Dense(64)(d1)
return Model(inputs=input, outputs=d2)
inner = create_inner_model()
# share layers for model
i1 = Input((10,))
i2 = Input((10,))
out1 = inner(i1)
out2 = inner(i2)
# concat output
concat = concatenate([out1, out2])
# output binary classification
out = Dense(2, activation='softmax')(concat)
final=Model(inputs=[i1, i2], outputs=out)
plot_model(final, to_file='final_model.png')
plot_model(inner, to_file='inner_model.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment