Skip to content

Instantly share code, notes, and snippets.

@svecon
Created August 29, 2017 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svecon/4e0321b1752cf1cbec59e57501dd3c73 to your computer and use it in GitHub Desktop.
Save svecon/4e0321b1752cf1cbec59e57501dd3c73 to your computer and use it in GitHub Desktop.
Remove last layers of Keras NN model
def remove_layers(model, n)
for _ in range(n):
model.pop()
model.outputs = [model.layers[-1].output]
model.layers[-1].outbound_nodes = []
model.compile(loss='binary_crossentropy', optimizer='adam')
return model
# Example
new_model = remove_layers(model.layers_by_depth[1][0])
new_model.summary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment