Callbacks

Callbacks that can be added to a model trainer’s main loop.

class ttools.callbacks.Callback[source]

Base class for all training callbacks.

epoch_end()[source]

Hook to execute code when an epoch ends.

Note: self.epoch is never incremented, but it is set externally in epoch_start.

epoch_start(epoch)[source]

Hook to execute code when a new epoch starts.

Note: self.epoch is never incremented. Instead, it should be set by the caller.

class ttools.callbacks.CheckpointingCallback(checkpointer, start_epoch=None, interval=600, max_files=5, max_epochs=10)[source]

A callback that periodically saves model checkpoints to disk.

Parameters:
  • checkpointer (Checkpointer) – actual checkpointer responsible for the I/O.
  • start_epoch (int or None) – index of the starting epoch (e.g. when resuming from a previous checkpoint).
  • interval (int, optional) – minimum time in seconds between periodic checkpoints (within an epoch). There is not periodic checkpoint if this value is None.
  • max_files (int, optional) – maximum number of periodic checkpoints to keep on disk.
  • max_epochs (int, optional) – maximum number of epoch checkpoints to keep on disk.
batch_end(batch_data, fwd_result, bwd_result)[source]

Save a periodic checkpoint if requested.

epoch_end()[source]

Save a checkpoint at the end of each epoch.

class ttools.callbacks.LoggingCallback(name, keys=None, val_keys=None, frequency=100, smoothing=0.99)[source]

A callback that logs scalar quantities to the console.

Make sure python’s logging level is at least info to see the console prints.

Parameters:
  • name (str) – name of the logger
  • keys (list of str) – list of keys whose values will be logged during training.
  • val_keys (list of str) – list of keys whose values will be logged during validation
batch_end(batch_data, fwd, bwd_data)[source]

Logs training advancement Epoch.Batch

epoch_start(epoch)[source]

Hook to execute code when a new epoch starts.

Note: self.epoch is never incremented. Instead, it should be set by the caller.

class ttools.callbacks.ImageDisplayCallback(frequency=100, server=None, port=8097, env='main', win=None)[source]

Displays image periodically to a Visdom server.

This is an abstract class, subclasses should implement the visualized_image method that synthesizes a [B, C, H, W] image to be visualized.

Parameters:
  • frequency (int) – number of optimization steps between two updates
  • port (int) – Port of the Visdom server to log to.
  • env (string) – name of the Visdom environment to log to.
class ttools.callbacks.ProgressBarCallback(keys=None, val_keys=None, smoothing=0.99)[source]

A progress bar optimization logger.

epoch_end()[source]

Hook to execute code when an epoch ends.

Note: self.epoch is never incremented, but it is set externally in epoch_start.

epoch_start(epoch)[source]

Hook to execute code when a new epoch starts.

Note: self.epoch is never incremented. Instead, it should be set by the caller.

class ttools.callbacks.VisdomLoggingCallback(keys=None, val_keys=None, frequency=100, server=None, port=8097, env='main', log=False, smoothing=0.99)[source]

A callback that logs scalar quantities to a visdom server.

Parameters:
  • keys (list of str) – list of keys whose values will be logged during training.
  • val_keys (list of str) – list of keys whose values will be logged during validation
  • frequency (int) – number of steps between display updates.
  • port (int) – Port of the Visdom server to log to.
  • env (string) – name of the Visdom environment to log to.
  • log (bool) – if True, shows the data on a log-scale
  • smoothing (float) – smoothing factor for the exponential moving average. 0.0 disables smoothing.
class ttools.callbacks.MultiPlotCallback(keys=None, val_keys=None, frequency=100, server=None, port=8097, env='main', log=False, smoothing=0.99, win=None)[source]

A callback that logs scalar quantities to a single Visdom window.

Parameters:
  • keys (list of str) – list of keys whose values will be logged during training.
  • val_keys (list of str) – list of keys whose values will be logged during validation
  • frequency (int) – number of steps between display updates.
  • port (int) – Port of the Visdom server to log to.
  • env (string) – name of the Visdom environment to log to.
  • log (bool) – if True, shows the data on a log-scale
  • smoothing (float) – smoothing factor for the exponential moving average. 0.0 disables smoothing.
  • win (str) – name of the window