0
0
TensorFlowml~10 mins

Callbacks (EarlyStopping, ModelCheckpoint) in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import EarlyStopping from TensorFlow Keras callbacks.

TensorFlow
from tensorflow.keras.callbacks import [1]
Drag options to blanks, or click blank then click option'
AModelCheckpoint
BTensorBoard
CReduceLROnPlateau
DEarlyStopping
Attempts:
3 left
💡 Hint
Common Mistakes
Importing ModelCheckpoint instead of EarlyStopping.
Trying to import from tensorflow.keras.models instead of callbacks.
2fill in blank
medium

Complete the code to create an EarlyStopping callback that monitors validation loss and stops if it doesn't improve for 3 epochs.

TensorFlow
early_stop = EarlyStopping(monitor='[1]', patience=3)
Drag options to blanks, or click blank then click option'
Aaccuracy
Bloss
Cval_loss
Dval_accuracy
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'loss' instead of 'val_loss' which monitors training loss.
Using 'accuracy' which is not the loss metric.
3fill in blank
hard

Fix the error in the code to save the best model weights only during training.

TensorFlow
checkpoint = ModelCheckpoint('best_model.h5', save_best_only=[1])
Drag options to blanks, or click blank then click option'
AFalse
BTrue
C'yes'
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'yes' instead of boolean True.
Using integer 1 which may work but is not recommended.
4fill in blank
hard

Fill both blanks to create a ModelCheckpoint that saves the model only when validation accuracy improves.

TensorFlow
checkpoint = ModelCheckpoint('model.h5', monitor='[1]', save_best_only=[2])
Drag options to blanks, or click blank then click option'
Aval_accuracy
Bval_loss
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Monitoring 'val_loss' instead of 'val_accuracy'.
Setting save_best_only to False which saves every epoch.
5fill in blank
hard

Fill all three blanks to create an EarlyStopping callback that monitors validation loss, waits 5 epochs before stopping, and restores the best weights.

TensorFlow
early_stop = EarlyStopping(monitor='[1]', patience=[2], restore_best_weights=[3])
Drag options to blanks, or click blank then click option'
Aval_loss
Bval_accuracy
C3
D5
ETrue
FFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'val_accuracy' instead of 'val_loss'.
Setting patience to 3 instead of 5.
Not restoring best weights by setting restore_best_weights to False.