victoresque / pytorch-template

PyTorch deep learning projects made easy.
MIT License
4.75k stars 1.09k forks source link

best_model is calculated based on save_epoch, not every epoch #72

Closed TonyLianLong closed 3 years ago

TonyLianLong commented 4 years ago

After setting the monitor to val accuracy, I would like to get the best model out of each epoch, but later on I found out that it is when epoch % save_epoch == 0 that best_model will be saved. This would cause the problem that models, with potentially better validation accuracy, are missed because they do not met condition to be saved, which does not seem to be a good idea.

This is the line that illustrates the problem: https://github.com/victoresque/pytorch-template/blob/f44498693fc4d3b20e412020116eec8c96e36c2e/base/base_trainer.py#L102

deeperlearner commented 3 years ago

https://github.com/victoresque/pytorch-template/blob/a39a102914feace71ddd05b58d5e5a7c0e2c99dd/base/base_trainer.py#L101

here should correct as if epoch % self.save_period == 0 or best: so that it can save best model in the case self.save_period > 1.