Skip to content

Instantly share code, notes, and snippets.

@sdcubber
Created September 15, 2018 13:50
Show Gist options
  • Save sdcubber/766763328d97f98f7c5a1d117d8389c6 to your computer and use it in GitHub Desktop.
Save sdcubber/766763328d97f98f7c5a1d117d8389c6 to your computer and use it in GitHub Desktop.
# Saving a model
network.save(filepath='./network.h5') # architecture + weights
network_json = network.to_json() # only the architecture
network.save_weights() # only the weights
# Restoring a saved model
new_network = keras.models.load_model('./another_model.h5')
# Using the ModelCheckpoint callback during training
callbacks = [
callbacks.ModelCheckpoint('./model.h5', verbose=1, save_best_only=True),
callbacks.EarlyStopping(monitor='val_loss', patience=2, verbose=1)
]
new_network.fit(train_images,
train_labels,
epochs=500,
batch_size=128,
validation_data=(val_images, val_labels),
callbacks=callbacks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment