fast.ai

class neptunecontrib.monitoring.fastai.NeptuneMonitor(experiment=None, learn=None, prefix='')[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Logs metrics from the fastai learner to Neptune.

Goes over the last_metrics and smooth_loss after each batch and epoch and logs them to appropriate Neptune channels.

See the example experiment here https://app.neptune.ml/neptune-ml/neptune-examples/e/NEP-493/charts.

Parameters:
  • ctx (neptune.Context) – Neptune context.
  • prefix (str) – Prefix that should be added before the metric_name and valid_name before logging to the appropriate channel. Defaul is ‘’.

Examples

Prepare data:

from fastai.vision import *
path = untar_data(URLs.MNIST_TINY)

data = ImageDataBunch.from_folder(path, ds_tfms=(rand_pad(2, 28), []), bs=64)
data.normalize(imagenet_stats)

learn = cnn_learner(data, models.resnet18, metrics=accuracy)

learn.lr_find()
learn.recorder.plot()

Now, create Neptune experiment, instantiate the monitor and pass it to callbacks:

import neptune
from neptunecontrib.monitoring.fastai import NeptuneMonitor

neptune.init(qualified_project_name='USER_NAME/PROJECT_NAME')

with neptune.create_experiment():
    monitor = NeptuneMonitor()
    learn = create_cnn(data, models.resnet18,
                       metrics=accuracy,
                       callbacks=[neptune_monitor])
    learn.fit_one_cycle(20, 1e-2)

Note

you need to have the fastai library installed on your computer to use this module.