What is the most likely reason training does not stop early?
medium
A. The validation data is not passed correctly, so val_loss is not computed
B. Patience is too low to allow stopping
C. EarlyStopping requires save_best_only=True to work
D. The model.fit call is missing the callbacks argument
Solution
Step 1: Check if validation data is correctly passed
EarlyStopping monitors validation metrics, so if validation data is missing or incorrect, val_loss won't update and stopping won't trigger.
Step 2: Evaluate other options
Patience=3 is reasonable, save_best_only is unrelated to EarlyStopping, and callbacks argument is present.
Final Answer:
The validation data is not passed correctly, so val_loss is not computed -> Option A
Quick Check:
EarlyStopping needs valid val_loss metric = D [OK]
Hint: EarlyStopping needs valid validation data to monitor val_loss [OK]
Common Mistakes:
Confusing ModelCheckpoint's save_best_only with EarlyStopping
Ignoring validation_data argument
Setting patience too high and expecting early stop
5. You want to train a model and save the best weights based on validation accuracy, but also stop training early if validation accuracy does not improve for 4 epochs. Which callback setup is correct?
hard
A. [tf.keras.callbacks.EarlyStopping(monitor='val_accuracy', patience=4), tf.keras.callbacks.ModelCheckpoint('best.h5', save_best_only=True, monitor='val_accuracy')]
B. [tf.keras.callbacks.EarlyStopping(monitor='accuracy', patience=4), tf.keras.callbacks.ModelCheckpoint('best.h5', save_best_only=False, monitor='val_accuracy')]
C. [tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=4), tf.keras.callbacks.ModelCheckpoint('best.h5', save_best_only=True, monitor='loss')]
D. [tf.keras.callbacks.EarlyStopping(monitor='val_accuracy', patience=2), tf.keras.callbacks.ModelCheckpoint('best.h5', save_best_only=True, monitor='val_accuracy')]
Solution
Step 1: Match EarlyStopping parameters to requirement
We want to stop if validation accuracy does not improve for 4 epochs, so monitor='val_accuracy' and patience=4 are correct.
Step 2: Match ModelCheckpoint parameters
We want to save best weights based on validation accuracy, so save_best_only=True and monitor='val_accuracy' are needed.
Step 3: Check options for both callbacks
Only [tf.keras.callbacks.EarlyStopping(monitor='val_accuracy', patience=4), tf.keras.callbacks.ModelCheckpoint('best.h5', save_best_only=True, monitor='val_accuracy')] has both callbacks correctly configured.
Final Answer:
[tf.keras.callbacks.EarlyStopping(monitor='val_accuracy', patience=4), tf.keras.callbacks.ModelCheckpoint('best.h5', save_best_only=True, monitor='val_accuracy')] -> Option A
Quick Check:
EarlyStopping and ModelCheckpoint monitor val_accuracy correctly = A [OK]
Hint: Match monitor and patience for both callbacks [OK]
Common Mistakes:
Using 'accuracy' instead of 'val_accuracy' for validation monitoring
Setting save_best_only=False when saving best model