Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TensorFlow · Class

callbacks.EarlyStopping

Stops Keras training when a monitored metric no longer improves. It can require a minimum improvement, tolerate a configured number of stalled epochs, use a baseline or warm-up period, and restore the best weights.

How it works

During Model.fit, the callback evaluates the selected metric after each epoch. It applies the chosen improvement direction, counts epochs without sufficient progress, and sets model.stop_training when patience is exhausted; optionally, it restores weights from the best observed epoch.

Syntax

tf.keras.callbacks.EarlyStopping(
    monitor='val_loss',
    min_delta=0,
    patience=0,
    verbose=0,
    mode='auto',
    baseline=None,
    restore_best_weights=False,
    start_from_epoch=0
)

Parameters

NameTypeDescription
monitorstrQuantity to monitor; defaults to val_loss.
min_deltafloatMinimum absolute change required to count as improvement; defaults to 0.
patienceintNumber of unimproved epochs tolerated; defaults to 0.
verboseintVerbosity mode, 0 or 1; defaults to 0.
modestrImprovement direction: auto, min, or max; defaults to auto.
baselinefloat or NoneOptional baseline for the monitored quantity.
restore_best_weightsboolWhether to restore weights from the best epoch; defaults to False.
start_from_epochintEpoch count to skip before monitoring; defaults to 0.

Key points

  • EarlyStopping is designed to terminate a Keras training run when progress in a selected metric plateaus.
  • The decision is made at epoch boundaries during the built-in fit loop.
  • When the stopping condition is met, the callback signals the model to end training.
  • min_delta defines the smallest absolute movement that counts as progress.
  • patience controls how long training tolerates a metric without improvement.
  • start_from_epoch provides a warm-up period before early stopping becomes active.

Example: Stop when validation loss plateaus

import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Input(shape=(10,)),
    tf.keras.layers.Dense(1)
])
model.compile(optimizer="adam", loss="mse")

stop = tf.keras.callbacks.EarlyStopping(
    monitor="val_loss",
    patience=3,
    restore_best_weights=True
)
model.fit(
    x_train, y_train,
    validation_split=0.2,
    epochs=50,
    callbacks=[stop]
)

Stops fitting when validation loss no longer improves and restores the weights from the best epoch.

When to use it

Limit unnecessary epochs

Validation performance plateaus during supervised training.

Skip an initial warm-up

A model may begin with unstable metrics.

Keep the best weights

The final stopping epoch may overfit relative to an earlier epoch.

Interview questions

QWhat does EarlyStopping do?

It is a Keras callback that stops training when a monitored metric stops improving. At the end of an epoch, Model.fit checks the metric and eventually marks model.stop_training as True.

Follow-up: How would you delay monitoring? Set start_from_epoch to the desired warm-up length so early epochs do not trigger stopping.

QHow are improvements evaluated?

monitor selects the quantity, while mode determines whether improvement means decreasing or increasing. auto infers the direction from the monitored quantity's name; min and max make it explicit.

Follow-up: When should mode be explicit? Use it when the metric name could make automatic direction inference ambiguous or when custom metrics have unusual names.

QHow do min_delta, patience, and restore_best_weights interact?

min_delta is the minimum absolute change required to count as improvement, and patience is the number of unimproved epochs tolerated. With patience set to zero, the first qualifying lack of improvement can stop training.

Follow-up: How can the final model retain the best epoch rather than the last epoch? Set restore_best_weights=True; otherwise, training ends with the weights from the stopping epoch.

  • tf.keras.callbacks.Callback
  • tf.keras.callbacks.ModelCheckpoint
  • tf.keras.callbacks.ReduceLROnPlateau
  • tf.keras.Model.fit

Source: tf.keras.callbacks.EarlyStopping | TensorFlow v2.16.1. Checked 2026-10-15.