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之间同步缓存。默认不同步。
"""
常用配置字典,一般直接写在主配置文件里,覆盖 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