【MMDET】checkpoint_config
时间:2021-04-22 09:11:55
收藏:0
阅读:24
MMDetection 的配置文件都是普通的 Python 文件,各种配置是以字典的形式编写的。
其实每个字典都是某个类的构造函数的参数,字典中的 type 就是类名,build_from_cfg 函数根据 type 字段的值和相应 Registry 对象中保存的映射关系,将配置字典中的参数传入并实例化一个相应类的对象。
checkpoint_config 是官方提供的默认运行时配置文件 default_runtime.py 的第一行内容,对应于 MMCV 中的 mmcv.runner.hooks.logger.CheckpointHook 类,构造参数如下:
@HOOKS.register_module()
class CheckpointHook(Hook):
"""Save checkpoints periodically.
定期保存检查点文件。
Args:
interval (int): The saving period. If ``by_epoch=True``, interval
indicates epochs, otherwise it indicates iterations.
Default: -1, which means "never".
保存周期,单位是epoch或iter。默认是-1,意思是不保存。
by_epoch (bool): Saving checkpoints by epoch or by iteration.
Default: True.
单位是epoch还是iter。默认是epoch。
save_optimizer (bool): Whether to save optimizer state_dict in the
checkpoint. It is usually used for resuming experiments.
Default: True.
是否保存optimizer的state_dict,可以用于继续实验(训练/测试)。
默认保存。
out_dir (str, optional): The directory to save checkpoints. If not
specified, ``runner.work_dir`` will be used by default.
保存检查点文件的目录。不指定将使用runner的work_dir。
max_keep_ckpts (int, optional): The maximum checkpoints to keep.
In some cases we want only the latest few checkpoints and would
like to delete old ones to save the disk space.
Default: -1, which means unlimited.
最多保存几个检查点文件,比如只保存最近的若干个。默认不限制个数。
save_last (bool): Whether to force the last checkpoint to be saved
regardless of interval. Default: True.
是否强制保存最后一个检查点文件,而不考虑是否到达了一个周期。默认保存。
sync_buffer (bool): Whether to synchronize buffers in different
gpus. Default: False.
是否在不同的GPU之间同步缓存。默认不同步。
"""
- interval:通常指定为 1
- by_epoch:一般就是用 EpochBasedRunner,保持默认即可
- save_optimizer:一般是需要保存的,方便断点继续训练
- out_dir:可以把检查点文件和日志文件分开,放到一个单独的目录,比如 ../../checkpoints,注意配置文件里的路径是相对于当前文件,而不是相对于执行训练/测试脚本的路径
- max_keep_ckpts:默认不限制个数,也就是说如果 interval 是 1,训练 100 个 epoch 会保存 100 个检查点文件,不是特别有必要,我一般设为 1,只保存最新的检查点文件
- save_last:也是有必要的
- sync_buffer:用于分布式训练,通常用不到
常用配置字典,一般直接写在主配置文件里,覆盖 default_runtime.py 中的配置:
checkpoint_config = dict(
interval=1,
out_dir=‘../../checkpoints‘,
max_keep_ckpts=1)
原文:https://www.cnblogs.com/huzheyu/p/mmdet-checkpoint-config.html
评论(0)