Progress and logging callbacks

Open In Colab

Callback and helper function to track progress of training or log results

  1. /usr/local/lib/python3.8/dist-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
  2. return torch._C._cuda_getDeviceCount() > 0
  1. from fastai.test_utils import *

class ProgressCallback[source]

ProgressCallback(after_create=None, before_fit=None, before_epoch=None, before_train=None, before_batch=None, after_pred=None, after_loss=None, before_backward=None, before_step=None, after_cancel_step=None, after_step=None, after_cancel_batch=None, after_batch=None, after_cancel_train=None, after_train=None, before_validate=None, after_cancel_validate=None, after_validate=None, after_cancel_epoch=None, after_epoch=None, after_cancel_fit=None, after_fit=None) :: Callback

A Callback to handle the display of progress bars

  1. learn = synth_learner()
  2. learn.fit(5)
epochtrain_lossvalid_losstime
08.9602218.50148600:00
17.6503685.47590800:00
26.1931273.20242500:00
34.9027141.78196900:00
43.8476870.96869900:00

Learner.no_bar[source]

Learner.no_bar()

Context manager that deactivates the use of progress bars

  1. learn = synth_learner()
  2. with learn.no_bar(): learn.fit(5)
  1. [0, 16.774219512939453, 16.614517211914062, '00:00']
  2. [1, 14.62364387512207, 11.538640975952148, '00:00']
  3. [2, 12.198295593261719, 7.462512016296387, '00:00']
  4. [3, 9.962362289428711, 4.619643688201904, '00:00']
  5. [4, 8.045241355895996, 2.791717052459717, '00:00']

ProgressCallback.before_fit[source]

ProgressCallback.before_fit()

Setup the master bar over the epochs

ProgressCallback.before_epoch[source]

ProgressCallback.before_epoch()

Update the master bar

ProgressCallback.before_train[source]

ProgressCallback.before_train()

Launch a progress bar over the training dataloader

ProgressCallback.before_validate[source]

ProgressCallback.before_validate()

Launch a progress bar over the validation dataloader

ProgressCallback.after_batch[source]

ProgressCallback.after_batch()

Update the current progress bar

ProgressCallback.after_train[source]

ProgressCallback.after_train()

Close the progress bar over the training dataloader

ProgressCallback.after_validate[source]

ProgressCallback.after_validate()

Close the progress bar over the validation dataloader

ProgressCallback.after_fit[source]

ProgressCallback.after_fit()

Close the master bar

class ShowGraphCallback[source]

ShowGraphCallback(after_create=None, before_fit=None, before_epoch=None, before_train=None, before_batch=None, after_pred=None, after_loss=None, before_backward=None, before_step=None, after_cancel_step=None, after_step=None, after_cancel_batch=None, after_batch=None, after_cancel_train=None, after_train=None, before_validate=None, after_cancel_validate=None, after_validate=None, after_cancel_epoch=None, after_epoch=None, after_cancel_fit=None, after_fit=None) :: Callback

Update a graph of training and validation loss

  1. learn = synth_learner(cbs=ShowGraphCallback())
  2. learn.fit(5)
epochtrain_lossvalid_losstime
011.6761618.62295700:00
110.1839966.06967200:00
28.5199483.89060900:00
36.9595602.38228800:00
45.6212201.41485800:00

Progress - 图2

  1. learn.predict(torch.tensor([[0.1]]))
  1. (tensor([1.9139]), tensor([1.9139]), tensor([1.9139]))

class CSVLogger[source]

CSVLogger(fname='history.csv', append=False) :: Callback

Log the results displayed in learn.path/fname

The results are appended to an existing file if append, or they overwrite it otherwise.

  1. learn = synth_learner(cbs=CSVLogger())
  2. learn.fit(5)
epochtrain_lossvalid_losstime
010.5009908.33102400:00
19.1150925.78339100:00
27.5739163.69532300:00
36.1611082.22286100:00
44.9484951.30883500:00

CSVLogger.read_log[source]

CSVLogger.read_log()

Convenience method to quickly access the log.

  1. df = learn.csv_logger.read_log()
  2. test_eq(df.columns.values, learn.recorder.metric_names)
  3. for i,v in enumerate(learn.recorder.values):
  4. test_close(df.iloc[i][:3], [i] + v)
  5. os.remove(learn.path/learn.csv_logger.fname)

CSVLogger.before_fit[source]

CSVLogger.before_fit()

Prepare file with metric names.

CSVLogger.after_fit[source]

CSVLogger.after_fit()

Close the file and clean up.


Company logo

©2021 fast.ai. All rights reserved.
Site last generated: Mar 31, 2021