Skip to content

Instantly share code, notes, and snippets.

@jainanchit51
Created February 3, 2019 09:35
Show Gist options
  • Save jainanchit51/7a4145185f322d10133ffccb12d4cf2c to your computer and use it in GitHub Desktop.
Save jainanchit51/7a4145185f322d10133ffccb12d4cf2c to your computer and use it in GitHub Desktop.
from keras.callbacks import ModelCheckpoint
# Creating the tensorflow session to train the model and save checkpoint after every epoch.
with tf.Session() as session:
K.set_session(session)
session.run(tf.global_variables_initializer())
session.run(tf.tables_initializer())
filepath="drive/My Drive/Colab Notebooks/Northout/model-{epoch:02d}-{val_acc:.2f}.hdf5"
checkpoint = ModelCheckpoint(filepath, monitor='val_loss', verbose=0, save_best_only=False, save_weights_only=True, mode='auto', period=1)
callbacks_list = [checkpoint]
history = model.fit([train_q1, train_q2],
train_labels,
validation_data=([test_q1, test_q2], test_labels),
epochs=10,
batch_size=512, callbacks=callbacks_list)
# model.save('drive/My Drive/Colab Notebooks/Northout/final_model.h5')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment