From 85e1f595ecf205d8b5db642d513b91dc32e1150d Mon Sep 17 00:00:00 2001 From: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com> Date: Tue, 28 Mar 2023 19:37:37 +0800 Subject: [PATCH] Apply suggestions from code review --- docs/en/tutorials/hook.md | 2 +- mmengine/hooks/checkpoint_hook.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/en/tutorials/hook.md b/docs/en/tutorials/hook.md index 9eeb67a01b..912f7502b8 100644 --- a/docs/en/tutorials/hook.md +++ b/docs/en/tutorials/hook.md @@ -123,7 +123,7 @@ The four features mentioned above are described below. - Make checkpoints for publish - If you want to automatically generate publishable checkpoints after training (remove unnecessary keys, such as optimizer state), you can set the `published_keys` parameter to choose which information to keep. Note: You need to set the `save_best` or `save_last` parameters accordingly, so that the releasable checkpoints will be generated. Setting `save_best` will generate the releasable weights of the optimal checkpoint, and setting `save_last` will generate the releasable final checkpoint. These two parameters can also be used set at the same time. + If you want to automatically generate publishable checkpoints after training (remove unnecessary keys, such as optimizer state), you can set the `published_keys` parameter to choose which information to keep. Note: You need to set the `save_best` or `save_last` parameters accordingly so that the releasable checkpoints will be generated. Setting `save_best` will generate the releasable weights of the optimal checkpoint, and setting `save_last` will generate the releasable final checkpoint. These two parameters can also be set at the same time. ```python default_hooks = dict(checkpoint=dict(type='CheckpointHook', interval=1, save_best='accuracy', rule='less', published_keys=['meta', 'state_dict'])) diff --git a/mmengine/hooks/checkpoint_hook.py b/mmengine/hooks/checkpoint_hook.py index 4e747007e6..1ea475f4ff 100644 --- a/mmengine/hooks/checkpoint_hook.py +++ b/mmengine/hooks/checkpoint_hook.py @@ -90,6 +90,7 @@ class CheckpointHook(Hook): or ``save_best`` is not ``None``, it will automatically publish model with keys in the list after training. Defaults to None. + `New in version 0.7.1.` Examples: >>> # Save best based on single metric >>> CheckpointHook(interval=2, by_epoch=True, save_best='acc', @@ -370,10 +371,10 @@ def _publish_model(self, runner, ckpt_path: str) -> None: logger='current') checkpoint_data = pickle.dumps(checkpoint) sha = hashlib.sha256(checkpoint_data).hexdigest() - final_path = osp.splitext(ckpt_path)[0] + f'-published-{sha[:8]}.pth' + final_path = osp.splitext(ckpt_path)[0] + f'-{sha[:8]}.pth' save_checkpoint(checkpoint, final_path) print_log( - f'The published model ({ckpt_path}) is saved at ' + f'The checkpoint ({ckpt_path}) is published to ' f'{final_path}.', logger='current')