Callback

class paddle.callbacks. Callback [source]

Base class used to build new callbacks. And new callbacks could also terminate training by setting model.stop_training=True.

Examples

>>> import paddle

>>> # build a simple model checkpoint callback
>>> class ModelCheckpoint(paddle.callbacks.Callback):
...     def __init__(self, save_freq=1, save_dir=None):
...         self.save_freq = save_freq
...         self.save_dir = save_dir
...
...     def on_epoch_end(self, epoch, logs=None):
...         if self.model is not None and epoch % self.save_freq == 0:
...             path = '{}/{}'.format(self.save_dir, epoch)
...             print('save checkpoint at {}'.format(path))
...             self.model.save(path)
set_params ( params )

set_params

Set parameters, which is dict. The keys contain:

  • ‘batch_size’: an integer. Number of samples per batch.

  • ‘epochs’: an integer. Number of epochs.

  • ‘steps’: an integer. Number of steps of one epoch.

  • ‘verbose’: an integer. Verbose mode is 0, 1 or 2. 0 = silent, 1 = progress bar, 2 = one line per epoch.

  • ‘metrics’: a list of str. Names of metrics, including ‘loss’ and the names of paddle.metric.Metric.

set_model ( model )

set_model

model is instance of paddle.Model.

on_train_begin ( logs=None )

on_train_begin

Called at the start of training.

Parameters

logs (dict) – The logs is a dict or None.

on_train_end ( logs=None )

on_train_end

Called at the end of training.

Parameters

logs (dict) – The logs is a dict or None. The keys of logs passed by paddle.Model contains ‘loss’, metric names and batch_size.

on_eval_begin ( logs=None )

on_eval_begin

Called at the start of evaluation.

Parameters

logs (dict) – The logs is a dict or None. The keys of logs passed by paddle.Model contains ‘steps’ and ‘metrics’, The steps is number of total steps of validation dataset. The metrics is a list of str including ‘loss’ and the names of paddle.metric.Metric.

on_eval_end ( logs=None )

on_eval_end

Called at the end of evaluation.

Parameters

logs (dict) – The logs is a dict or None. The logs passed by paddle.Model is a dict contains ‘loss’, metrics and ‘batch_size’ of last batch of validation dataset.

on_predict_begin ( logs=None )

on_predict_begin

Called at the beginning of predict.

Parameters

logs (dict) – The logs is a dict or None.

on_predict_end ( logs=None )

on_predict_end

Called at the end of predict.

Parameters

logs (dict) – The logs is a dict or None.

on_epoch_begin ( epoch, logs=None )

on_epoch_begin

Called at the beginning of each epoch.

Parameters
  • epoch (int) – The index of epoch.

  • logs (dict) – The logs is a dict or None. The logs passed by paddle.Model is None.

on_epoch_end ( epoch, logs=None )

on_epoch_end

Called at the end of each epoch.

Parameters
  • epoch (int) – The index of epoch.

  • logs (dict) – The logs is a dict or None. The logs passed by paddle.Model is a dict, contains ‘loss’, metrics and ‘batch_size’ of last batch.

on_train_batch_begin ( step, logs=None )

on_train_batch_begin

Called at the beginning of each batch in training.

Parameters
  • step (int) – The index of step (or iteration).

  • logs (dict) – The logs is a dict or None. The logs passed by paddle.Model is empty.

on_train_batch_end ( step, logs=None )

on_train_batch_end

Called at the end of each batch in training.

Parameters
  • step (int) – The index of step (or iteration).

  • logs (dict) – The logs is a dict or None. The logs passed by paddle.Model is a dict, contains ‘loss’, metrics and ‘batch_size’ of current batch.

on_eval_batch_begin ( step, logs=None )

on_eval_batch_begin

Called at the beginning of each batch in evaluation.

Parameters
  • step (int) – The index of step (or iteration).

  • logs (dict) – The logs is a dict or None. The logs passed by paddle.Model is empty.

on_eval_batch_end ( step, logs=None )

on_eval_batch_end

Called at the end of each batch in evaluation.

Parameters
  • step (int) – The index of step (or iteration).

  • logs (dict) – The logs is a dict or None. The logs passed by paddle.Model is a dict, contains ‘loss’, metrics and ‘batch_size’ of current batch.

on_predict_batch_begin ( step, logs=None )

on_predict_batch_begin

Called at the beginning of each batch in predict.

Parameters
  • step (int) – The index of step (or iteration).

  • logs (dict) – The logs is a dict or None.

on_predict_batch_end ( step, logs=None )

on_predict_batch_end

Called at the end of each batch in predict.

Parameters
  • step (int) – The index of step (or iteration).

  • logs (dict) – The logs is a dict or None.