In [ ]:
from fastai.vision import *
from fastai.gen_doc.nbdoc import *
from fastai.callbacks import *
In [ ]:
show_doc(CSVLogger)
First let's show an example of use, with a training on the usual MNIST dataset.
In [ ]:
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])
In [ ]:
learn.fit(3)
Training details have been saved in 'history.csv'.
Note that it only saves float/int metrics, so time currently is not saved. This could be saved but requires changing the recording - you can submit a PR fixing that.
In [ ]:
learn.path.ls()
Out[ ]:
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
.
In [ ]:
show_doc(CSVLogger.read_logged_file)
In [ ]:
learn.csv_logger.read_logged_file()
Out[ ]:
Optionally you can set append=True
to log results of consequent stages of training.
In [ ]:
# don't forget to remove the old file
if learn.csv_logger.path.exists(): os.remove(learn.csv_logger.path)
In [ ]:
learn = Learner(data, simple_cnn((3, 16, 16, 2)), metrics=[accuracy, error_rate],
callback_fns=[partial(CSVLogger, append=True)])
In [ ]:
# stage-1
learn.fit(3)
In [ ]:
# stage-2
learn.fit(3)
In [ ]:
learn.csv_logger.read_logged_file()
Out[ ]:
You don't call these yourself - they're called by fastai's Callback
system automatically to enable the class's functionality.
In [ ]:
show_doc(CSVLogger.on_train_begin)
In [ ]:
show_doc(CSVLogger.on_epoch_end)
In [ ]:
show_doc(CSVLogger.on_train_end)