mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
feat: save checkpoint before deleting old ones (#1453)
* feat: save checkpoint before deleting old ones * fix: make sure that the new model is not deleted * changelog Co-authored-by: J. Borovec <jirka.borovec@seznam.cz> Co-authored-by: William Falcon <waf2107@columbia.edu>
This commit is contained in:
co-authored by
J. Borovec
William Falcon
parent
2ab2f7d08d
commit
9b31272cf0
@@ -34,6 +34,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
- Fixed saving checkpoint before deleting old ones ([#1453](https://github.com/PyTorchLightning/pytorch-lightning/pull/1453))
|
||||
|
||||
- Fixed loggers - flushing last logged metrics even before continue, e.g. `trainer.test()` results ([#1459](https://github.com/PyTorchLightning/pytorch-lightning/pull/1459))
|
||||
|
||||
- Added a missing call to the `on_before_zero_grad` model hook ([#1493](https://github.com/PyTorchLightning/pytorch-lightning/pull/1493)).
|
||||
|
||||
@@ -216,10 +216,12 @@ class ModelCheckpoint(Callback):
|
||||
|
||||
def _do_check_save(self, filepath, current, epoch):
|
||||
# remove kth
|
||||
|
||||
del_list = []
|
||||
if len(self.best_k_models) == self.save_top_k and self.save_top_k > 0:
|
||||
delpath = self.kth_best_model
|
||||
self.best_k_models.pop(self.kth_best_model)
|
||||
self._del_model(delpath)
|
||||
del_list.append(delpath)
|
||||
|
||||
self.best_k_models[filepath] = current
|
||||
if len(self.best_k_models) == self.save_top_k:
|
||||
@@ -238,3 +240,7 @@ class ModelCheckpoint(Callback):
|
||||
f' {current:0.5f} (best {self.best:0.5f}), saving model to'
|
||||
f' {filepath} as top {self.save_top_k}')
|
||||
self._save_model(filepath)
|
||||
|
||||
for cur_path in del_list:
|
||||
if cur_path != filepath:
|
||||
self._del_model(cur_path)
|
||||
|
||||
Reference in New Issue
Block a user