I have a learner I’m training. Is there any way to get its current training and validation loss? Something like this would be ideal:
TrainLoss, ValidLoss = learn.loss()
Does this exist within FastAI? I’m sure I’m just missing something. Thank you all in advance.
you can use:
result, ep_vals = learn.fit(…, get_ep_vals=True)
Then you can get training and validation loss for each epoch.
You can see an example
https://github.com/adriangrepo/my_fastai/blob/master/dl2/translate.ipynb just before the Test section heading where I plot these to get a feel for how things are progressing.
Thank you for the reply. Unfortunately, this isn’t working for me. It seems learn.fit doesn’t accept that as an argument. The fit function appears to be:
def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):
if reset_opt or not self.opt: self.create_opt()
if wd is None: wd = self.wd
if wd is not None: self.opt.set_hypers(wd=wd)
self.opt.set_hypers(lr=self.lr if lr is None else lr)
self.n_epoch = n_epoch
self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
Upon checking your linked github, the notebook does not load. I get the following.
Download the whole repository and navigate to that specific file and check the code, because i can’t upload the .ipynb file directly here, and you will find what you need
or maybe this helps (This is a code snippet from the repository. - line 111)
vals_s2s, ep_vals_s2s = learn.fit(lr, n_cycle=1, cycle_len=12, use_clr=(20,10), get_ep_vals=True)
epochs = ep_vals.keys()
trn_losses = [item for item in list(ep_vals.values())]
val_losses = [item for item in list(ep_vals.values())]
plt.plot(epochs, trn_losses, c='b', label='train')
plt.plot(epochs, val_losses, c='r', label='validation')
I hope this helps
learn.recorder.loss has it IIRC. Its either loss or losses