Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
if save_model_flag:
# Add optimization method, loss function and optimization value
optimizer='adam', metrics=['accuracy'])
# "Fit the model" (train model), using training data (80% of datset), y_train, batch_size=batch_size,
epochs=epochs, validation_data=(x_test, y_test))
# Save model to json file
model_json = model.to_json()
with open(model_name + ".json", "w") as json_file:
# serialize weights to HDF5
model.save_weights(model_name + ".h5")
# load json and create model
json_file = open(model_name + '.json', 'r')
loaded_model_json =
model = model_from_json(loaded_model_json)
# load weights into new model
model.load_weights(model_name + ".h5")
# evaluate loaded model on test data
optimizer='adam', metrics=['accuracy'])
# Evaluate the trained model, using the test data (20% of the dataset)
score = model.evaluate(x_test, y_test, batch_size=batch_size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.