From 5baf7721e17789ee7bdcb49c44ea987ab898d0ad Mon Sep 17 00:00:00 2001 From: Antonio Lanza Date: Thu, 17 Jun 2021 19:07:29 +0200 Subject: [PATCH 1/4] Change dict update order --- mmcv/runner/epoch_based_runner.py | 7 +++---- mmcv/runner/iter_based_runner.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/mmcv/runner/epoch_based_runner.py b/mmcv/runner/epoch_based_runner.py index 1e1de295ed..721446c01a 100644 --- a/mmcv/runner/epoch_based_runner.py +++ b/mmcv/runner/epoch_based_runner.py @@ -149,14 +149,13 @@ 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 = dict() + 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) + 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 75133d5ec4..f19d7fe58c 100644 --- a/mmcv/runner/iter_based_runner.py +++ b/mmcv/runner/iter_based_runner.py @@ -193,14 +193,13 @@ 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 = dict() + 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) + meta.update(epoch=self.epoch + 1, iter=self.iter) filename = filename_tmpl.format(self.iter + 1) filepath = osp.join(out_dir, filename) From 19b39042d9657ff670081a3f2bc3d5d95f0f81c9 Mon Sep 17 00:00:00 2001 From: Antonio Lanza Date: Fri, 18 Jun 2021 12:43:02 +0200 Subject: [PATCH 2/4] Change dict() with {} --- mmcv/runner/epoch_based_runner.py | 2 +- mmcv/runner/iter_based_runner.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mmcv/runner/epoch_based_runner.py b/mmcv/runner/epoch_based_runner.py index 721446c01a..895ecbe9da 100644 --- a/mmcv/runner/epoch_based_runner.py +++ b/mmcv/runner/epoch_based_runner.py @@ -149,7 +149,7 @@ def save_checkpoint(self, Defaults to True. """ if meta is None: - meta = dict() + meta = {} elif not isinstance(meta, dict): raise TypeError( f'meta should be a dict or None, but got {type(meta)}') diff --git a/mmcv/runner/iter_based_runner.py b/mmcv/runner/iter_based_runner.py index f19d7fe58c..9d6b1d28b1 100644 --- a/mmcv/runner/iter_based_runner.py +++ b/mmcv/runner/iter_based_runner.py @@ -193,7 +193,7 @@ def save_checkpoint(self, latest checkpoint file. Defaults to True. """ if meta is None: - meta = dict() + meta = {} elif not isinstance(meta, dict): raise TypeError( f'meta should be a dict or None, but got {type(meta)}') From 2ba652cce19e282309271e5b70d53e39ccb5a82f Mon Sep 17 00:00:00 2001 From: Antonio Lanza Date: Mon, 28 Jun 2021 13:27:38 +0200 Subject: [PATCH 3/4] Added comments with PR link --- mmcv/runner/epoch_based_runner.py | 2 ++ mmcv/runner/iter_based_runner.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/mmcv/runner/epoch_based_runner.py b/mmcv/runner/epoch_based_runner.py index 895ecbe9da..f3f6942719 100644 --- a/mmcv/runner/epoch_based_runner.py +++ b/mmcv/runner/epoch_based_runner.py @@ -155,6 +155,8 @@ def save_checkpoint(self, 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) diff --git a/mmcv/runner/iter_based_runner.py b/mmcv/runner/iter_based_runner.py index 9d6b1d28b1..0d16cf6418 100644 --- a/mmcv/runner/iter_based_runner.py +++ b/mmcv/runner/iter_based_runner.py @@ -199,6 +199,8 @@ def save_checkpoint(self, 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) From 9f36da0973d4e2949b61717a08297a23a48f2415 Mon Sep 17 00:00:00 2001 From: Antonio Lanza Date: Mon, 28 Jun 2021 14:00:52 +0200 Subject: [PATCH 4/4] Fixed comments according to Lint Job --- mmcv/runner/epoch_based_runner.py | 6 ++++-- mmcv/runner/iter_based_runner.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mmcv/runner/epoch_based_runner.py b/mmcv/runner/epoch_based_runner.py index f3f6942719..fcc0eafac1 100644 --- a/mmcv/runner/epoch_based_runner.py +++ b/mmcv/runner/epoch_based_runner.py @@ -155,8 +155,10 @@ def save_checkpoint(self, 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 + # 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) diff --git a/mmcv/runner/iter_based_runner.py b/mmcv/runner/iter_based_runner.py index 0d16cf6418..db4de484fc 100644 --- a/mmcv/runner/iter_based_runner.py +++ b/mmcv/runner/iter_based_runner.py @@ -199,8 +199,10 @@ def save_checkpoint(self, 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 + # 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)