Fast.ai Reference

wandb.fastai

source

This module hooks fast.ai Learners to Weights & Biases through a callback. Requested logged data can be configured through the callback constructor.

Examples:

WandbCallback can be used when initializing the Learner::

from wandb.fastai import WandbCallback
[...]
learn = Learner(data, ..., callback_fns=WandbCallback)
learn.fit(epochs)

Custom parameters can be given using functools.partial::

from wandb.fastai import WandbCallback
from functools import partial
[...]
learn = Learner(data, ..., callback_fns=partial(WandbCallback, ...))
learn.fit(epochs)

Finally, it is possible to use WandbCallback only when starting training. In this case it must be instantiated::

learn.fit(..., callbacks=WandbCallback(learn))

or, with custom parameters::

learn.fit(..., callbacks=WandbCallback(learn, ...))

WandbCallback

source

WandbCallback(self,
learn,
log='gradients',
save_model=True,
monitor=None,
mode='auto',
input_type=None,
validation_data=None,
predictions=36,
seed=12345)

Automatically saves model topology, losses & metrics. Optionally logs weights, gradients, sample predictions and best trained model.

Arguments:

  • learn fastai.basic_train.Learner - the fast.ai learner to hook.

  • log str - "gradients", "parameters", "all", or None. Losses & metrics are always logged.

  • save_model bool - save model at the end of each epoch. It will also load best model at the end of training.

  • monitor str - metric to monitor for saving best model. None uses default TrackerCallback monitor value.

  • mode str - "auto", "min" or "max" to compare "monitor" values and define best model.

  • input_type str - "images" or None. Used to display sample predictions.

  • validation_data list - data used for sample predictions if input_type is set.

  • predictions int - number of predictions to make if input_type is set and validation_data is None.

  • seed int - initialize random generator for sample predictions if input_type is set and validation_data is None.

WandbCallback.on_train_begin

source

WandbCallback.on_train_begin(self, **kwargs)

Call watch method to log model topology, gradients & weights

WandbCallback.on_epoch_end

source

WandbCallback.on_epoch_end(self, epoch, smooth_loss, last_metrics, **kwargs)

Logs training loss, validation loss and custom metrics & log prediction samples & save model

WandbCallback.on_train_end

source

WandbCallback.on_train_end(self, **kwargs)

Load the best model.