Package ai.djl.training.listener
Class EvaluatorTrainingListener
- java.lang.Object
-
- ai.djl.training.listener.TrainingListenerAdapter
-
- ai.djl.training.listener.EvaluatorTrainingListener
-
- All Implemented Interfaces:
TrainingListener
public class EvaluatorTrainingListener extends TrainingListenerAdapter
TrainingListenerthat 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 forprogressUpdateFrequencybatches 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 Modifier and Type Field Description static java.lang.StringTRAIN_ALLstatic java.lang.StringTRAIN_EPOCHstatic java.lang.StringTRAIN_PROGRESSstatic java.lang.StringVALIDATE_EPOCH
-
Constructor Summary
Constructors Constructor Description EvaluatorTrainingListener()Constructs anEvaluatorTrainingListenerthat updates the training progress the default frequency.EvaluatorTrainingListener(int progressUpdateFrequency)Constructs anEvaluatorTrainingListenerthat updates the training progress the given frequency.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Float>getLatestEvaluations()Returns the latest evaluations.static java.lang.StringmetricName(Evaluator evaluator, java.lang.String stage)Returns the metric created with the evaluator for the given stage.voidonEpoch(Trainer trainer)Listens to the end of an epoch during training.voidonTrainingBatch(Trainer trainer, TrainingListener.BatchData batchData)Listens to the end of training one batch of data during training.voidonTrainingBegin(Trainer trainer)Listens to the beginning of training.voidonValidationBatch(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 Detail
-
TRAIN_EPOCH
public static final java.lang.String TRAIN_EPOCH
- See Also:
- Constant Field Values
-
TRAIN_PROGRESS
public static final java.lang.String TRAIN_PROGRESS
- See Also:
- Constant Field Values
-
TRAIN_ALL
public static final java.lang.String TRAIN_ALL
- See Also:
- Constant Field Values
-
VALIDATE_EPOCH
public static final java.lang.String VALIDATE_EPOCH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EvaluatorTrainingListener
public EvaluatorTrainingListener()
Constructs anEvaluatorTrainingListenerthat updates the training progress the default frequency.Current default frequency is every 5 batches.
-
EvaluatorTrainingListener
public EvaluatorTrainingListener(int progressUpdateFrequency)
Constructs anEvaluatorTrainingListenerthat 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 Detail
-
onEpoch
public void onEpoch(Trainer trainer)
Listens to the end of an epoch during training.- Specified by:
onEpochin interfaceTrainingListener- Overrides:
onEpochin classTrainingListenerAdapter- Parameters:
trainer- the trainer the listener is attached to
-
onTrainingBatch
public void onTrainingBatch(Trainer trainer, TrainingListener.BatchData batchData)
Listens to the end of training one batch of data during training.- Specified by:
onTrainingBatchin interfaceTrainingListener- Overrides:
onTrainingBatchin classTrainingListenerAdapter- Parameters:
trainer- the trainer the listener is attached tobatchData- the data from the batch
-
onValidationBatch
public void onValidationBatch(Trainer trainer, TrainingListener.BatchData batchData)
Listens to the end of validating one batch of data during validation.- Specified by:
onValidationBatchin interfaceTrainingListener- Overrides:
onValidationBatchin classTrainingListenerAdapter- Parameters:
trainer- the trainer the listener is attached tobatchData- the data from the batch
-
onTrainingBegin
public void onTrainingBegin(Trainer trainer)
Listens to the beginning of training.- Specified by:
onTrainingBeginin interfaceTrainingListener- Overrides:
onTrainingBeginin classTrainingListenerAdapter- Parameters:
trainer- the trainer the listener is attached to
-
metricName
public static java.lang.String metricName(Evaluator evaluator, java.lang.String stage)
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
public java.util.Map<java.lang.String,java.lang.Float> getLatestEvaluations()
Returns the latest evaluations.The latest evaluations are updated on each epoch.
- Returns:
- the latest evaluations
-
-