Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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