Skip to content

Commit

Permalink
[Fix] add eval hook resume test code
Browse files Browse the repository at this point in the history
  • Loading branch information
linyq17 committed Dec 30, 2021
1 parent 05267dd commit 132250a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions mmfewshot/classification/core/evaluation/eval_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def before_run(self, runner: Runner) -> None:
warnings.warn('runner.meta is None. Creating an empty one.')
runner.meta = dict()
runner.meta.setdefault('hook_msgs', dict())
self.best_score = runner.meta.get('best_score', 0.0)
if self.best_score > 0.0:
if runner.meta['hook_msgs'].get('best_score', False):
self.best_score = runner.meta['hook_msgs']['best_score']
runner.logger.info(
f'Previous best score is: {self.best_score}.')
self.best_ckpt_path = runner.meta['hook_msgs'].get(
Expand Down Expand Up @@ -140,7 +140,6 @@ def _save_ckpt(self, runner: Runner, key_score: float) -> None:

if self.best_score < key_score:
self.best_score = key_score
runner.meta['best_score'] = self.best_score
runner.meta['hook_msgs']['best_score'] = self.best_score
runner.meta['hook_msgs']['ckpt_time'] = current

Expand All @@ -152,10 +151,7 @@ def _save_ckpt(self, runner: Runner, key_score: float) -> None:
runner.meta['hook_msgs']['best_ckpt'] = self.best_ckpt_path

runner.save_checkpoint(
runner.work_dir,
best_ckpt_name,
meta={'best_score': self.best_score},
create_symlink=False)
runner.work_dir, best_ckpt_name, create_symlink=False)
runner.logger.info(
f'Now best checkpoint is saved as {best_ckpt_name}.')
runner.logger.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ def test_resume_eval_hook():
logger=logging.getLogger(),
max_epochs=1)
runner.register_hook(eval_hook)
runner.meta = {'best_score': 99.0}
runner.meta = {'hook_msgs': {'best_score': 99.0}}
runner.run([loader], [('train', 1)], 1)
assert eval_hook.best_score == 99.0

0 comments on commit 132250a

Please # to comment.