ProgBarLogger

class paddle.callbacks. ProgBarLogger ( log_freq=1, verbose=2 ) [source]

Logger callback function to print loss and metrics to stdout. It supports silent mode (not print), progress bar or one line per each printing, see arguments for more detailed.

Parameters
  • log_freq (int) – The frequency, in number of steps, the logs such as loss, metrics are printed. Default: 1.

  • verbose (int) – The verbosity mode, should be 0, 1, or 2. 0 = silent, 1 = progress bar, 2 = one line each printing, 3 = 2 + time counter, such as average reader cost, samples per second. Default: 2.

Examples

import paddle
import paddle.vision.transforms as T
from paddle.vision.datasets import MNIST
from paddle.static import InputSpec

inputs = [InputSpec([-1, 1, 28, 28], 'float32', 'image')]
labels = [InputSpec([None, 1], 'int64', 'label')]

transform = T.Compose([
    T.Transpose(),
    T.Normalize([127.5], [127.5])
])
train_dataset = MNIST(mode='train', transform=transform)

lenet = paddle.vision.LeNet()
model = paddle.Model(lenet,
    inputs, labels)

optim = paddle.optimizer.Adam(0.001, parameters=lenet.parameters())
model.prepare(optimizer=optim,
            loss=paddle.nn.CrossEntropyLoss(),
            metrics=paddle.metric.Accuracy())

callback = paddle.callbacks.ProgBarLogger(log_freq=10)
model.fit(train_dataset, batch_size=64, callbacks=callback)
on_train_begin ( logs=None )

Called at the start of training.

Parameters

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

on_epoch_begin ( epoch=None, logs=None )

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_train_batch_begin ( step, logs=None )

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 )

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_epoch_end ( epoch, logs=None )

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_eval_begin ( logs=None )

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_batch_begin ( step, logs=None )

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 )

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_begin ( logs=None )

Called at the beginning of predict.

Parameters

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

on_predict_batch_begin ( step, logs=None )

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 )

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.

on_eval_end ( logs=None )

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_end ( logs=None )

Called at the end of predict.

Parameters

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