Skip to content

Instantly share code, notes, and snippets.

@notha99y
Last active November 27, 2018 08:55
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 notha99y/2a77c36f698ad0e94ee691f1fcef0187 to your computer and use it in GitHub Desktop.
Save notha99y/2a77c36f698ad0e94ee691f1fcef0187 to your computer and use it in GitHub Desktop.
# Importing the Callbacks
from keras.callbacks import EarlyStopping
from keras.callbacks import TensorBoard
from keras.callbacks import ModelCheckpoint
# Saving logs
LOG_DIR = os.path.join(os.getcwd(), 'logs')
tb = TensorBoard(LOG_DIR)
# Saving weights
weights_dir = 'weights/' + model.name + \
'-{epoch:02d}-{loss:.2f}.hdf5'
chkpt = ModelCheckpoint(filepath=weights_dir, monitor='loss', save_best_only=True, save_weights_only=True, mode='auto', period=1)
# Stop training when val_acc is not improving after 5 epochs
early_stop = EarlyStopping(monitor='val_acc', min_delta=0, patience=5)
history = model.fit(X_train, Y_train, epochs=50, batch_size=3, validation_data = (X_test, Y_test), callbacks=[tb, chkpt, early_stop])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment