Callbacks that saves the tracked metrics during training

CSV Logger

class CSVLogger[source]

CSVLogger(learn:Learner, filename:str='history') :: LearnerCallback

A LearnerCallback that saves history of metrics while training learn into CSV filename.

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

path = untar_data(URLs.MNIST_TINY)
data = ImageDataBunch.from_folder(path)
learn = Learner(data, simple_cnn((3, 16, 16, 2)), metrics=[accuracy, error_rate], callback_fns=[CSVLogger])
learn.fit(3)
Total time: 00:01
epoch  train_loss  valid_loss  accuracy  error_rate
1      0.677579    0.630915    0.929900  0.070100    (00:00)
2      0.596842    0.341453    0.928469  0.071531    (00:00)
3      0.470232    0.203056    0.938484  0.061516    (00:00)

Training details have been saved in 'history.csv'.

learn.path.ls()
[PosixPath('/home/ubuntu/.fastai/data/mnist_tiny/train'),
 PosixPath('/home/ubuntu/.fastai/data/mnist_tiny/test'),
 PosixPath('/home/ubuntu/.fastai/data/mnist_tiny/labels.csv'),
 PosixPath('/home/ubuntu/.fastai/data/mnist_tiny/valid'),
 PosixPath('/home/ubuntu/.fastai/data/mnist_tiny/history.csv'),
 PosixPath('/home/ubuntu/.fastai/data/mnist_tiny/models')]

Note that, as with all LearnerCallback, you can access the object as an attribute of learn after it has been created. Here it's learn.csv_logger.

read_logged_file[source]

read_logged_file()

Read the content of saved file

learn.csv_logger.read_logged_file()
epoch train_loss valid_loss accuracy error_rate
0 1 2.286365 2.216762 0.505007 0.494993
1 2 2.168981 1.867415 0.505007 0.494993
2 3 2.028238 1.743607 0.505007 0.494993