EarlyStopping

class EarlyStopping(monitor: KProperty1<EpochTrainingEvent, Double?>, minDelta: Double, patience: Int, verbose: Boolean, mode: EarlyStoppingMode, baseline: Double, restoreBestWeights: Boolean) : Callback

This callback stops training when a monitored metric has stopped improving.

Assuming the goal of a training is to minimize the loss. With this, the metric to be monitored would be 'loss', and mode would be 'min'. A model.fit() training loop will check at end of every epoch whether the loss is no longer decreasing, considering the min_delta and patience if applicable. Once it's found no longer decreasing, model.stop_training is marked True and the training terminates.

The quantity to be monitored needs to be available in logs. To make it so, pass the loss or metrics at model.compile().

Constructors

EarlyStopping
Link copied to clipboard
fun EarlyStopping(monitor: KProperty1<EpochTrainingEvent, Double?> = EpochTrainingEvent::lossValue, minDelta: Double = 0.0, patience: Int = 0, verbose: Boolean = false, mode: EarlyStoppingMode = EarlyStoppingMode.AUTO, baseline: Double = 0.001, restoreBestWeights: Boolean = false)

Creates an EarlyStopping Callback.

Functions

onEpochBegin
Link copied to clipboard
open fun onEpochBegin(epoch: Int, logs: TrainingHistory)

Called at the start of an epoch during training phase.

onEpochEnd
Link copied to clipboard
open override fun onEpochEnd(epoch: Int, event: EpochTrainingEvent, logs: TrainingHistory)

Called at the end of an epoch during training phase.

onPredictBatchBegin
Link copied to clipboard
open fun onPredictBatchBegin(batch: Int, batchSize: Int)

Called at the beginning of a batch during prediction phase.

onPredictBatchEnd
Link copied to clipboard
open fun onPredictBatchEnd(batch: Int, batchSize: Int)

Called at the end of a batch during prediction phase.

onPredictBegin
Link copied to clipboard
open fun onPredictBegin()

Called at the beginning of prediction.

onPredictEnd
Link copied to clipboard
open fun onPredictEnd()

Called at the end of prediction.

onTestBatchBegin
Link copied to clipboard
open fun onTestBatchBegin(batch: Int, batchSize: Int, logs: History)

Called at the beginning of a batch during evaluation phase. Also called at the beginning of a validation batch during validation phase, if validation data is provided.

onTestBatchEnd
Link copied to clipboard
open fun onTestBatchEnd(batch: Int, batchSize: Int, event: BatchEvent?, logs: History)

Called at the end of a batch during evaluation phase. Also called at the end of a validation batch during validation phase, if validation data is provided.

onTestBegin
Link copied to clipboard
open fun onTestBegin()

Called at the beginning of evaluation or validation.

onTestEnd
Link copied to clipboard
open fun onTestEnd(logs: History)

Called at the end of evaluation or validation.

onTrainBatchBegin
Link copied to clipboard
open fun onTrainBatchBegin(batch: Int, batchSize: Int, logs: TrainingHistory)

Called at the beginning of a batch during training phase.

onTrainBatchEnd
Link copied to clipboard
open fun onTrainBatchEnd(batch: Int, batchSize: Int, event: BatchTrainingEvent, logs: TrainingHistory)

Called at the end of a batch during training phase.

onTrainBegin
Link copied to clipboard
open override fun onTrainBegin()

Called at the beginning of training.

onTrainEnd
Link copied to clipboard
open override fun onTrainEnd(logs: TrainingHistory)

Called at the end of training. This method is empty. Extend this class to handle this event.