from fastai import *
from fastai.vision import *
from fastai.gen_doc.nbdoc import *
from fastai.callbacks import *
show_doc(CSVLogger)
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.
show_doc(CSVLogger.read_logged_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 |
show_doc(CSVLogger.on_train_end)
on_train_end[source]
on_train_end(kwargs:Any)
Useful for cleaning up things and saving files/models.
show_doc(CSVLogger.on_epoch_end)
on_epoch_end[source]
on_epoch_end(epoch:int,smooth_loss:Tensor,last_metrics:MetricsList,kwargs:Any) →bool
Called at the end of an epoch.
show_doc(CSVLogger.on_train_begin)
on_train_begin[source]
on_train_begin(metrics_names:StrList,kwargs:Any)
To initialize constants in the callback.