1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Deep Learning with Keras

Connected

Exercise

A combination of callbacks

Deep learning models can take a long time to train, especially when you move to deeper architectures and bigger datasets. Saving your model every time it improves as well as stopping it when it no longer does allows you to worry less about choosing the number of epochs to train for. You can also restore a saved model anytime and resume training where you left it.

The model training and validation data are available in your workspace as X_train, X_test, y_train, and y_test.

Use the EarlyStopping() and the ModelCheckpoint() callbacks so that you can go eat a jar of cookies while you leave your computer to work!

Instructions

100 XP
  • Import both the EarlyStopping and ModelCheckpoint callbacks from tensorflow.keras.
  • Create monitor_val_acc as an EarlyStopping callback that will monitor 'val_accuracy', with a patience of 3 epochs.
  • Create model_checkpoint as a ModelCheckpointcallback, save the best model as best_banknote_model.hdf5.
  • Fit your model providing a list with the defined callbacks and X_test and y_test as validation data.