Callbacks that saves the tracked metrics during training and output logs for tensorboard to read

Tensorboard

Load tensorboard magic command to show tensorboard embed in jupyter notebook.

%load_ext tensorboard

class LearnerTensorboardWriter[source][test]

LearnerTensorboardWriter(learn:Learner, base_dir:Path, name:str, loss_iters:int=25, hist_iters:int=500, stats_iters:int=100) :: LearnerCallback

No tests found for LearnerTensorboardWriter. To contribute a test please refer to this guide and this discussion.

Broadly useful callback for Learners that writes to Tensorboard. Writes model histograms, losses/metrics, and gradient stats.

First let's show an example of use, with a training on the MovieLens sample dataset.

path = untar_data(URLs.ML_SAMPLE)

ratings = pd.read_csv(path/'ratings.csv')
series2cat(ratings, 'userId', 'movieId')
data = CollabDataBunch.from_df(ratings, seed=42)

learn = collab_learner(data, n_factors=30, y_range = [0, 5.5])

Specify log path for tensorboard to read from. Then append callback partial to learner callback functions.

project_id = 'projct1'
tboard_path = Path('data/tensorboard/' + project_id)
learn.callback_fns.append(partial(LearnerTensorboardWriter, 
                                    base_dir=tboard_path, 
                                    name='run1'))

run tensorboard magic command with logdir parameter. Default port is 6006.

%tensorboard --logdir=$tboard_path --port=6006

Or you can launch the Tensorboard server from shell with tensorboard --logdir=data/tensorboard/project1 --port=6006 then navigate to http://localhost:6006

learn.fit(10)

Calback methods

You don't call these yourself - they're called by fastai's Callback system automatically to enable the class's functionality.

on_train_begin[source][test]

on_train_begin(**kwargs:Any)

No tests found for on_train_begin. To contribute a test please refer to this guide and this discussion.

To initialize constants in the callback.

on_batch_end[source][test]

on_batch_end(last_loss:Tensor, iteration:int, train:bool, **kwargs)

No tests found for on_batch_end. To contribute a test please refer to this guide and this discussion.

Callback function that writes batch end appropriate data to Tensorboard.

on_backward_end[source][test]

on_backward_end(iteration:int, train:bool, **kwargs)

No tests found for on_backward_end. To contribute a test please refer to this guide and this discussion.

Callback function that writes backward end appropriate data to Tensorboard.

on_epoch_end[source][test]

on_epoch_end(last_metrics:MetricsList, iteration:int, **kwargs)

No tests found for on_epoch_end. To contribute a test please refer to this guide and this discussion.

Callback function that writes epoch end appropriate data to Tensorboard.