WandbCallback

class paddle.callbacks. WandbCallback ( project=None, entity=None, name=None, dir=None, mode=None, job_type=None, **kwargs ) [source]

Track your training and system metrics using Weights and Biases.

Installation and set-up

Install with pip and log in to your W&B account:

pip install wandb
wandb login
Parameters
  • project (str, optional) – Name of the project. Default: uncategorized

  • entity (str, optional) – Name of the team/user creating the run. Default: Logged in user

  • name (str, optional) – Name of the run. Default: randomly generated by wandb

  • dir (str, optional) – Directory in which all the metadata is stored. Default: wandb

  • mode (str, optional) – Can be “online”, “offline” or “disabled”. Default: “online”.

  • job_type (str, optional) – the type of run, for grouping runs together. Default: None

Examples

>>> import paddle
>>> import paddle.vision.transforms as T
>>> 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 = paddle.vision.datasets.MNIST(mode='train', transform=transform)
>>> eval_dataset = paddle.vision.datasets.MNIST(mode='test', transform=transform)

>>> net = paddle.vision.models.LeNet()
>>> model = paddle.Model(net, inputs, labels)

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

>>> ## uncomment following lines to fit model with wandb callback function
>>> # callback = paddle.callbacks.WandbCallback(project='paddle_mnist')
>>> # model.fit(train_dataset, eval_dataset, batch_size=64, callbacks=callback)
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_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_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_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_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_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.