early-stopping-pytorch icon indicating copy to clipboard operation
early-stopping-pytorch copied to clipboard

early-stopping-pytorch.py, shouldn't the script save previous model?

Open brucewlee opened this issue 2 years ago • 1 comments

Hi. Thanks for your resources :) They are giving great help to my research.

BTW, isn't it correct to save the previous model when the loss decreases? It seems like your current early-stopping-pytorch.py script is intended to save the current model, not the previous one.

brucewlee avatar May 29 '22 10:05 brucewlee

self.best_score = score self.save_checkpoint(val_loss, model)

def save_checkpoint(self, val_loss, model): '''Saves model when validation loss decrease.''' if self.verbose: self.trace_func(f'Validation loss decreased ({self.val_loss_min:.6f} --> {val_loss:.6f}). Saving model ...') torch.save(model.state_dict(), self.path)

save the best model

bioinformatica avatar Jun 29 '22 01:06 bioinformatica