INNER CODE UNIT · Python
_save
timeseriesAI/tsai · tsai/callback/core.py:135
def _save(self, name): self.last_saved_path = self.learn.save(name, with_opt=self.with_opt)
def after_epoch(self):
"Compare the value monitored to its best score and save if best."
if self.every_epoch:
if (self.epoch%self.every_epoch) == 0: self._save(f'{self.fname}_{self.epoch}')
else: #every improvement
super().after_epoch()
if self.new_best:
pv(f'Better model found at epoch {self.epoch} with {self.monitor} value: {self.best}.', self.verbose)
self._save(f'{self.fname}')
def after_fit(self, **kwargs):
"Load the best model."
if self.at_end: self._save(f'{self.fname}')
elif not self.every_epoch: self.learn.load(f'{self.fname}', with_opt=self.with_opt)
# %% ../../nbs/024_callback.core.ipynb #c916484a