I could not get your example to run but. Here is a code like this can buildsample where a new model built from parts of an existing model:
# Explicitly define new model input and output by slicing out old model layers
model_new = Model(input=model_old.layers[0].input,
output=model_old.layers[12].output)
# Compile model to inspect
model_new.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
# Visually inspect new model to confirm it the correct architecture
model_new.summary()
# Explicitly define new model input and output by slicing out old model layers
model_new = Model(input=model_old.layers[0].input,
output=model_old.layers[12].output)
# Compile model to inspect
model_new.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
# Visually inspect new model to confirm it has the correct architecture
model_new.summary()