What are listeners?

Listeners allow users to “hook” into certain events in Eclipse Deeplearning4j. This allows you to collect or print information useful for tasks like training. For example, a ScoreIterationListener allows you to print training scores from the output layer of a neural network.

Usage

To add one or more listeners to a MultiLayerNetwork or ComputationGraph, use the addListener method:

  1. MultiLayerNetwork model = new MultiLayerNetwork(conf);
  2. model.init();
  3. //print the score with every 1 iteration
  4. model.setListeners(new ScoreIterationListener(1));

Available listeners


EvaluativeListener

[source]

This TrainingListener implementation provides simple way for model evaluation during training.It can be launched every Xth Iteration/Epoch, depending on frequency and InvocationType constructor arguments

EvaluativeListener
  1. public EvaluativeListener(@NonNull DataSetIterator iterator, int frequency)

This callback will be invoked after evaluation finished

iterationDone
  1. public void iterationDone(Model model, int iteration, int epoch)
  • param iterator Iterator to provide data for evaluation
  • param frequency Frequency (in number of iterations/epochs according to the invocation type) to perform evaluation
  • param type Type of value for ‘frequency’ - iteration end, epoch end, etc

Checkpoint

[source]


ScoreIterationListener

[source]

Score iteration listener. Reports the score (value of the loss function )of the network during training everyN iterations

ScoreIterationListener
  1. public ScoreIterationListener(int printIterations)
  • param printIterations frequency with which to print scores (i.e., every printIterations parameter updates)

ComposableIterationListener

[source]

A group of listeners


CollectScoresIterationListener

[source]

CollectScoresIterationListener simply stores the model scores internally (along with the iteration) every 1 or Niterations (this is configurable). These scores can then be obtained or exported.

CollectScoresIterationListener
  1. public CollectScoresIterationListener()

Constructor for collecting scores with default saving frequency of 1

iterationDone
  1. public void iterationDone(Model model, int iteration, int epoch)

Constructor for collecting scores with the specified frequency.

  • param frequency Frequency with which to collect/save scores
exportScores
  1. public void exportScores(OutputStream outputStream) throws IOException

Export the scores in tab-delimited (one per line) UTF-8 format.

exportScores
  1. public void exportScores(OutputStream outputStream, String delimiter) throws IOException

Export the scores in delimited (one per line) UTF-8 format with the specified delimiter

  • param outputStream Stream to write to
  • param delimiter Delimiter to use
exportScores
  1. public void exportScores(File file) throws IOException

Export the scores to the specified file in delimited (one per line) UTF-8 format, tab delimited

  • param file File to write to
exportScores
  1. public void exportScores(File file, String delimiter) throws IOException

Export the scores to the specified file in delimited (one per line) UTF-8 format, using the specified delimiter

  • param file File to write to
  • param delimiter Delimiter to use for writing scores

CheckpointListener

[source]

CheckpointListener: The goal of this listener is to periodically save a copy of the model during training..Model saving may be done:

  • Every N epochs
  • Every N iterations
  • Every T time units (every 15 minutes, for example)Or some combination of the 3.Example 1: Saving a checkpoint every 2 epochs, keep all model files
  1. .keepAll() //Don't delete any models
  2. .saveEveryNEpochs(2)
  3. .build()
  4. }

Example 2: Saving a checkpoint every 1000 iterations, but keeping only the last 3 models (all older modelfiles will be automatically deleted)

  1. .keepLast(3)
  2. .saveEveryNIterations(1000)
  3. .build();
  4. }

Example 3: Saving a checkpoint every 15 minutes, keeping the most recent 3 and otherwise every 4th checkpointfile:

  1. .keepLastAndEvery(3, 4)
  2. .saveEvery(15, TimeUnit.MINUTES)
  3. .build();
  4. }

Note that you can mix these: for example, to save every epoch and every 15 minutes (independent of last save time):To save every epoch, and every 15 minutes, since the last model save use:Note that is this last example, the sinceLast parameter is true. This means the 15-minute counter will bereset any time a model is saved.

CheckpointListener
  1. public CheckpointListener build()

List all available checkpoints. A checkpoint is ‘available’ if the file can be loaded. Any checkpoint files thathave been automatically deleted (given the configuration) will not be returned here.

  • return List of checkpoint files that can be loaded

SharedGradient

[source]


SleepyTrainingListener

[source]

This TrainingListener implementation provides a way to “sleep” during specific Neural Network training phases.Suitable for debugging/testing purposes only.

PLEASE NOTE: All timers treat time values as milliseconds.PLEASE NOTE: Do not use it in production environment.

onEpochStart
  1. public void onEpochStart(Model model)

In this mode parkNanos() call will be used, to make process really idle


CollectScoresListener

[source]

A simple listener that collects scores to a list every N iterations. Can also optionally log the score.


PerformanceListener

[source]

Simple IterationListener that tracks time spend on training per iteration.

PerformanceListener
  1. public PerformanceListener build()

This method defines, if iteration number should be reported together with other data

  • param reportIteration
  • return

ParamAndGradientIterationListener

[source]

An iteration listener that provides details on parameters and gradients at each iteration during traning.Attempts to provide much of the same information as the UI histogram iteration listener, but in a text-basedformat (for example, when learning on a system accessed via SSH etc).i.e., is intended to aid network tuning and debuggingThis iteration listener is set up to calculate mean, min, max, and mean absolute valueof each type of parameter and gradient in the network at each iteration.


TimeIterationListener

[source]

Time Iteration Listener.This listener displays into INFO logs the remaining time in minutes and the date of the end of the process.Remaining time is estimated from the amount of time for training so far, and the total number of iterationsspecified by the user

TimeIterationListener
  1. public TimeIterationListener(int iterationCount)

Constructor

  • param iterationCount The global number of iteration for training (all epochs)