Skip to content

Callback in training

# MXNet.mx.AbstractBatchCallbackType.

AbstractBatchCallback

Abstract type of callbacks to be called every mini-batch.

source

# MXNet.mx.AbstractCallbackType.

AbstractCallback

Abstract type of callback functions used in training.

source

# MXNet.mx.AbstractEpochCallbackType.

AbstractEpochCallback

Abstract type of callbacks to be called every epoch.

source

# MXNet.mx.do_checkpointMethod.

do_checkpoint(prefix; frequency=1, save_epoch_0=false)

Create an AbstractEpochCallback that save checkpoints of the model to disk. The checkpoints can be loaded back later on.

Arguments

  • prefix::AbstractString: the prefix of the filenames to save the model. The model architecture will be saved to prefix-symbol.json, while the weights will be saved to prefix-0012.params, for example, for the 12-th epoch.
  • frequency::Int: keyword argument, default is 1. The frequency (measured in epochs) to save checkpoints.
  • save_epoch_0::Bool: keyword argument, default false. Whether we should save a checkpoint for epoch 0 (model initialized but not seen any data yet).

source

# MXNet.mx.every_n_batchMethod.

every_n_batch(callback :: Function, n :: Int; call_on_0 = false)

A convenient function to construct a callback that runs every n mini-batches.

Arguments

  • call_on_0::Bool: keyword argument, default false. Unless set, the callback will not be run on batch 0.

For example, the speedometer callback is defined as

every_n_batch(frequency, call_on_0=true) do state :: OptimizationState
  if state.curr_batch == 0
    # reset timer
  else
    # compute and print speed
  end
end

See also every_n_epoch and speedometer.

source

# MXNet.mx.every_n_epochMethod.

every_n_epoch(callback :: Function, n :: Int; call_on_0 = false)

A convenient function to construct a callback that runs every n full data-passes.

  • call_on_0::Bool: keyword argument, default false. Unless set, the callback will not be run on epoch 0. Epoch 0 means no training has been performed yet. This is useful if you want to inspect the randomly initialized model that has not seen any data yet.

See also every_n_batch.

source

# MXNet.mx.speedometerMethod.

speedometer(;frequency=50)

Create an AbstractBatchCallback that measure the training speed (number of samples processed per second) every k mini-batches.

Arguments

  • frequency::Int: keyword argument, default 50. The frequency (number of min-batches) to measure and report the speed.

source