Skip to content

Commit

Permalink
Change dict update order (#1108)
Browse files Browse the repository at this point in the history
* Change dict update order

* Change dict() with {}

* Added comments with PR link

* Fixed comments according to Lint Job
  • Loading branch information
antoniolanza1996 committed Jun 29, 2021
1 parent 1d5ee6e commit b035fe9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions mmcv/runner/epoch_based_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions mmcv/runner/iter_based_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b035fe9

Please sign in to comment.