From b035fe9171ce1913beb911870099fc4dff6689c9 Mon Sep 17 00:00:00 2001 From: Antonio Lanza Date: Tue, 29 Jun 2021 16:11:21 +0200 Subject: [PATCH] Change dict update order (#1108) * Change dict update order * Change dict() with {} * Added comments with PR link * Fixed comments according to Lint Job --- mmcv/runner/epoch_based_runner.py | 11 +++++++---- mmcv/runner/iter_based_runner.py | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mmcv/runner/epoch_based_runner.py b/mmcv/runner/epoch_based_runner.py index b95f2a1f68..baf072f18f 100644 --- a/mmcv/runner/epoch_based_runner.py +++ b/mmcv/runner/epoch_based_runner.py @@ -151,14 +151,17 @@ def save_checkpoint(self, Defaults to True. """ if meta is None: - meta = dict(epoch=self.epoch + 1, iter=self.iter) - elif isinstance(meta, dict): - meta.update(epoch=self.epoch + 1, iter=self.iter) - else: + meta = {} + elif not isinstance(meta, dict): raise TypeError( f'meta should be a dict or None, but got {type(meta)}') if self.meta is not None: meta.update(self.meta) + # Note: meta.update(self.meta) should be done before + # meta.update(epoch=self.epoch + 1, iter=self.iter) otherwise + # there will be problems with resumed checkpoints. + # More details in https://github.com/open-mmlab/mmcv/pull/1108 + meta.update(epoch=self.epoch + 1, iter=self.iter) filename = filename_tmpl.format(self.epoch + 1) filepath = osp.join(out_dir, filename) diff --git a/mmcv/runner/iter_based_runner.py b/mmcv/runner/iter_based_runner.py index 62a46216dd..b35d1823e2 100644 --- a/mmcv/runner/iter_based_runner.py +++ b/mmcv/runner/iter_based_runner.py @@ -195,14 +195,17 @@ def save_checkpoint(self, latest checkpoint file. Defaults to True. """ if meta is None: - meta = dict(iter=self.iter + 1, epoch=self.epoch + 1) - elif isinstance(meta, dict): - meta.update(iter=self.iter + 1, epoch=self.epoch + 1) - else: + meta = {} + elif not isinstance(meta, dict): raise TypeError( f'meta should be a dict or None, but got {type(meta)}') if self.meta is not None: meta.update(self.meta) + # Note: meta.update(self.meta) should be done before + # meta.update(epoch=self.epoch + 1, iter=self.iter) otherwise + # there will be problems with resumed checkpoints. + # More details in https://github.com/open-mmlab/mmcv/pull/1108 + meta.update(epoch=self.epoch + 1, iter=self.iter) filename = filename_tmpl.format(self.iter + 1) filepath = osp.join(out_dir, filename)