Early stopping your model
The early stopping callback is useful since it allows for you to stop the model training if it no longer improves after a given number of epochs. To make use of this functionality you need to pass the callback inside a list to the model's callback parameter in the .fit() method.
The model you built to detect fake dollar bills is loaded for you to train, this time with early stopping. X_train, y_train, X_test and y_test are also available for your use.
This exercise is part of the course
Introduction to Deep Learning with Keras
Exercise instructions
- Import the EarlyStoppingcallback fromtensorflow.keras.callbacks.
- Define a callback, monitor 'val_accuracy'with apatienceof 5 epochs.
- Train your model using the early stopping callback.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the early stopping callback
from tensorflow.____.____ import ____
# Define a callback to monitor val_accuracy
monitor_val_acc = ____(monitor=____, 
                       patience=____)
# Train your model using the early stopping callback
model.____(____, ____, 
           epochs=1000, validation_data=____,
           callbacks= ____)