From acc5215097ad69fbbdfbf99c26495cfa10477850 Mon Sep 17 00:00:00 2001 From: takuoko Date: Wed, 20 Oct 2021 17:24:52 +0900 Subject: [PATCH] [Fix] Set the priority of `EvalHook` to "LOW" to avoid a bug of `IterBasedRunner` (#488) * Set the priority of EvalHook to LOW. * add a comment --- mmcls/apis/train.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mmcls/apis/train.py b/mmcls/apis/train.py index 186d927d46c..4206f973d98 100644 --- a/mmcls/apis/train.py +++ b/mmcls/apis/train.py @@ -151,7 +151,11 @@ def train_model(model, eval_cfg = cfg.get('evaluation', {}) eval_cfg['by_epoch'] = cfg.runner['type'] != 'IterBasedRunner' eval_hook = DistEvalHook if distributed else EvalHook - runner.register_hook(eval_hook(val_dataloader, **eval_cfg)) + # `EvalHook` needs to be executed after `IterTimerHook`. + # Otherwise, it will cause a bug if use `IterBasedRunner`. + # Refers to https://github.com/open-mmlab/mmcv/issues/1261 + runner.register_hook( + eval_hook(val_dataloader, **eval_cfg), priority='LOW') if cfg.resume_from: runner.resume(cfg.resume_from)