Package ai.djl.training.listener
Class EvaluatorTrainingListener
java.lang.Object
ai.djl.training.listener.TrainingListenerAdapter
ai.djl.training.listener.EvaluatorTrainingListener
- All Implemented Interfaces:
TrainingListener
TrainingListener
that records evaluator results.
Results are recorded for the following stages:
TRAIN_EPOCH
- This accumulates for the whole epoch and is recorded to a metric at the end of the epochTRAIN_PROGRESS
- This accumulates forprogressUpdateFrequency
batches and is recorded to a metric at the endTRAIN_ALL
- This does not accumulates and records every training batch to a metricVALIDATE_EPOCH
- This accumulates for the whole validation epoch and is recorded to a metric at the end of the epoch
The training and validation evaluators are saved as metrics with names that can be found using
metricName(Evaluator, String)
. The validation evaluators are
also saved as model properties with the evaluator name.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ai.djl.training.listener.TrainingListener
TrainingListener.BatchData, TrainingListener.Defaults
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs anEvaluatorTrainingListener
that updates the training progress the default frequency.EvaluatorTrainingListener
(int progressUpdateFrequency) Constructs anEvaluatorTrainingListener
that updates the training progress the given frequency. -
Method Summary
Modifier and TypeMethodDescriptionReturns the latest evaluations.static String
metricName
(Evaluator evaluator, String stage) Returns the metric created with the evaluator for the given stage.void
Listens to the end of an epoch during training.void
onTrainingBatch
(Trainer trainer, TrainingListener.BatchData batchData) Listens to the end of training one batch of data during training.void
onTrainingBegin
(Trainer trainer) Listens to the beginning of training.void
onValidationBatch
(Trainer trainer, TrainingListener.BatchData batchData) Listens to the end of validating one batch of data during validation.Methods inherited from class ai.djl.training.listener.TrainingListenerAdapter
onTrainingEnd
-
Field Details
-
TRAIN_EPOCH
- See Also:
-
TRAIN_PROGRESS
- See Also:
-
TRAIN_ALL
- See Also:
-
VALIDATE_EPOCH
- See Also:
-
-
Constructor Details
-
EvaluatorTrainingListener
public EvaluatorTrainingListener()Constructs anEvaluatorTrainingListener
that updates the training progress the default frequency.Current default frequency is every 5 batches.
-
EvaluatorTrainingListener
public EvaluatorTrainingListener(int progressUpdateFrequency) Constructs anEvaluatorTrainingListener
that updates the training progress the given frequency.- Parameters:
progressUpdateFrequency
- the number of batches to accumulate an evaluator before it is stable enough to output
-
-
Method Details
-
onEpoch
Listens to the end of an epoch during training.- Specified by:
onEpoch
in interfaceTrainingListener
- Overrides:
onEpoch
in classTrainingListenerAdapter
- Parameters:
trainer
- the trainer the listener is attached to
-
onTrainingBatch
Listens to the end of training one batch of data during training.- Specified by:
onTrainingBatch
in interfaceTrainingListener
- Overrides:
onTrainingBatch
in classTrainingListenerAdapter
- Parameters:
trainer
- the trainer the listener is attached tobatchData
- the data from the batch
-
onValidationBatch
Listens to the end of validating one batch of data during validation.- Specified by:
onValidationBatch
in interfaceTrainingListener
- Overrides:
onValidationBatch
in classTrainingListenerAdapter
- Parameters:
trainer
- the trainer the listener is attached tobatchData
- the data from the batch
-
onTrainingBegin
Listens to the beginning of training.- Specified by:
onTrainingBegin
in interfaceTrainingListener
- Overrides:
onTrainingBegin
in classTrainingListenerAdapter
- Parameters:
trainer
- the trainer the listener is attached to
-
metricName
Returns the metric created with the evaluator for the given stage.- Parameters:
evaluator
- the evaluator to read the metric fromstage
- one ofTRAIN_EPOCH
,TRAIN_PROGRESS
, orVALIDATE_EPOCH
- Returns:
- the metric name to use
-
getLatestEvaluations
Returns the latest evaluations.The latest evaluations are updated on each epoch.
- Returns:
- the latest evaluations
-