位置: IT常识 - 正文

MMDetection系列 | 5. MMDetection运行配置介绍(mmdetection optimizer)

编辑:rootadmin
MMDetection系列 | 5. MMDetection运行配置介绍

推荐整理分享MMDetection系列 | 5. MMDetection运行配置介绍(mmdetection optimizer),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:mmdetection中文手册,mmdetection中文手册,mmdetection optimizer,mmdetection resume,mmdetection介绍,mmdetection介绍,mmdetection详解,mmdetection介绍,内容如对您有帮助,希望把文章链接给更多的朋友!

如有错误,恳请指出。

开门见山,基于mmdet的官方文档直接介绍如何进行我们的运行配置。个人觉得,继承于default_runtime.py这个文件之后,主要需要自己稍微更改下的配置主要有7个,分别是:优化器配置、学习率配置、工作流程配置、检查点配置、日志配置、评估配置、训练设置。具体的配置流程如下所示。

如果需要其他钩子函数的实现与配置,具体可以查看参考资料1.

文章目录1. 优化器配置2. 学习率配置3. 工作流程配置4. 检查点配置5. 日志配置6. 评估配置7. 训练设置1. 优化器配置optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001)optimizer_config = dict(grad_clip=None)使用梯度剪辑来稳定训练optimizer_config = dict( _delete_=True, grad_clip=dict(max_norm=35, norm_type=2))

其中,_delete_=True将用新键替换backbone字段中的所有旧键

2. 学习率配置lr_config = dict( policy='step', warmup='linear', warmup_iters=500, warmup_ratio=0.001, step=[8, 11]) # 表示初始学习率在第8和11个epoch衰减10倍

还有其他的配置方案:

Poly schedulelr_config = dict(policy='poly', power=0.9, min_lr=1e-4, by_epoch=False)ConsineAnnealing schedulelr_config = dict( policy='CosineAnnealing', warmup='linear', warmup_iters=1000, warmup_ratio=1.0 / 10, min_lr_ratio=1e-5)使用动量调度加速模型收敛

支持动量调度器根据学习率修改模型的动量,这可以使模型以更快的方式收敛。Momentum 调度器通常与 LR 调度器一起使用

lr_config = dict( policy='cyclic', target_ratio=(10, 1e-4), cyclic_times=1, step_ratio_up=0.4,)momentum_config = dict( policy='cyclic', target_ratio=(0.85 / 0.95, 1), cyclic_times=1, step_ratio_up=0.4,)3. 工作流程配置

工作流是 (phase, epochs) 的列表,用于指定运行顺序和时期。默认情况下,它设置为:

workflow = [('train', 1)]

这意味着运行 1 个 epoch 进行训练。有时用户可能想要检查验证集上模型的一些指标(例如损失、准确性)。在这种情况下,我们可以将工作流设置为

[('train', 1), ('val', 1)]

这样 1 个 epoch 的训练和 1 个 epoch 的验证将被迭代运行。而验证集的损失同样会被计算出来。如果想先进行验证,再进行训练,还可以设置如下:

[('val', 1), ('train', n)]

这样设置表示先对验证集进行验证与损失计算,再进行n个epoch的计算。

4. 检查点配置checkpoint_config = dict(interval=20) # 20个epoch保存一次权重

参数说明见:https://mmcv.readthedocs.io/en/latest/api.html#mmcv.runner.CheckpointHook

CLASSmmcv.runner.CheckpointHook(interval: int = - 1, by_epoch: bool = True, save_optimizer: bool = True, out_dir: Optional[str] = None, max_keep_ckpts: int = - 1, save_last: bool = True, sync_buffer: bool = False, file_client_args: Optional[dict] = None, **kwargs)

interval (int) – The saving period. If by_epoch=True, interval indicates epochs, otherwise it indicates iterations. Default: -1, which means “never”.by_epoch (bool) – Saving checkpoints by epoch or by iteration. Default: True.save_optimizer (bool) – Whether to save optimizer state_dict in the checkpoint. It is usually used for resuming experiments. Default: True.out_dir (str, optional) – The root directory to save checkpoints. If not specified, runner.work_dir will be used by default. If specified, the out_dir will be the concatenation of out_dir and the last level directory of runner.work_dir. Changed in version 1.3.16.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, optional) – Whether to force the last checkpoint to be saved regardless of interval. Default: True.sync_buffer (bool, optional) – Whether to synchronize buffers in different gpus. Default: False.file_client_args (dict, optional) – Arguments to instantiate a FileClient. See mmcv.fileio.FileClient for details. Default: None. New in version 1.3.16.5. 日志配置MMDetection系列 | 5. MMDetection运行配置介绍(mmdetection optimizer)

包装多个记录器log_config挂钩并允许设置间隔。现在 MMCV 支持WandbLoggerHook、MlflowLoggerHook和TensorboardLoggerHook.

log_config = dict( interval=50, # 每500个迭代就打印一次训练信息 hooks=[ dict(type='TextLoggerHook'), # dict(type='TensorboardLoggerHook') ])

参数说明见:https://mmcv.readthedocs.io/en/latest/api.html#mmcv.runner.EvalHook

CLASSmmcv.runner.LoggerHook(interval: int = 10, ignore_last: bool = True, reset_flag: bool = False, by_epoch: bool = True)[SOURCE]

interval (int) – Logging interval (every k iterations). Default 10.ignore_last (bool) – Ignore the log of last iterations in each epoch if less than interval. Default True.reset_flag (bool) – Whether to clear the output buffer after logging. Default False.by_epoch (bool) – Whether EpochBasedRunner is used. Default True.6. 评估配置

配置的evaluation将用于初始化EvalHook. 除了 key interval,其他参数如metric将传递给dataset.evaluate() evaluation = dict(interval=1, metric=‘bbox’)

参数说明:https://mmcv.readthedocs.io/en/latest/api.html?highlight=EpochBasedRunner#mmcv.runner.EpochBasedRunner

mmcv.runner.EvalHook(dataloader: torch.utils.data.dataloader.DataLoader, start: Optional[int] = None, interval: int = 1, by_epoch: bool = True, save_best: Optional[str] = None, rule: Optional[str] = None, test_fn: Optional[Callable] = None, greater_keys: Optional[List[str]] = None, less_keys: Optional[List[str]] = None, out_dir: Optional[str] = None, file_client_args: Optional[dict] = None, **eval_kwargs)

dataloader (DataLoader) – A PyTorch dataloader, whose dataset has implemented evaluate function.start (int | None, optional) – Evaluation starting epoch. It enables evaluation before the training starts if start <= the resuming epoch. If None, whether to evaluate is merely decided by interval. Default: None.interval (int) – Evaluation interval. Default: 1.by_epoch (bool) – Determine perform evaluation by epoch or by iteration. If set to True, it will perform by epoch. Otherwise, by iteration. Default: True.save_best (str, optional) – If a metric is specified, it would measure the best checkpoint during evaluation. The information about best checkpoint would be saved in runner.meta[‘hook_msgs’] to keep best score value and best checkpoint path, which will be also loaded when resume checkpoint. Options are the evaluation metrics on the test dataset. e.g., bbox_mAP, segm_mAP for bbox detection and instance segmentation. AR@100 for proposal recall. If save_best is auto, the first key of the returned OrderedDict result will be used. Default: None.rule (str | None, optional) – Comparison rule for best score. If set to None, it will infer a reasonable rule. Keys such as ‘acc’, ‘top’ .etc will be inferred by ‘greater’ rule. Keys contain ‘loss’ will be inferred by ‘less’ rule. Options are ‘greater’, ‘less’, None. Default: None.test_fn (callable, optional) – test a model with samples from a dataloader, and return the test results. If None, the default test function mmcv.engine.single_gpu_test will be used. (default: None)greater_keys (List[str] | None, optional) – Metric keys that will be inferred by ‘greater’ comparison rule. If None, _default_greater_keys will be used. (default: None)less_keys (List[str] | None, optional) – Metric keys that will be inferred by ‘less’ comparison rule. If None, _default_less_keys will be used. (default: None)out_dir (str, optional) – The root directory to save checkpoints. If not specified, runner.work_dir will be used by default. If specified, the out_dir will be the concatenation of out_dir and the last level directory of runner.work_dir. New in version 1.3.16.file_client_args (dict) – Arguments to instantiate a FileClient. See mmcv.fileio.FileClient for details. Default: None. New in version 1.3.16.**eval_kwargs – Evaluation arguments fed into the evaluate function of the dataset.7. 训练设置runner = dict(type='EpochBasedRunner', max_epochs=150) # 设置模型训练多少次

参数说明:https://mmcv.readthedocs.io/en/latest/api.html#mmcv.runner.EpochBasedRunner

mmcv.runner.EpochBasedRunner(model: torch.nn.modules.module.Module, batch_processor: Optional[Callable] = None, optimizer: Optional[Union[Dict, torch.optim.optimizer.Optimizer]] = None, work_dir: Optional[str] = None, logger: Optional[logging.Logger] = None, meta: Optional[Dict] = None, max_iters: Optional[int] = None, max_epochs: Optional[int] = None)

总结:

一般来说,我们写配置文件都会继承default_runtime.py这个文件

_base_ = [ '../_base_/default_runtime.py']

这个文件的内容如下所示:

checkpoint_config = dict(interval=5) # 每5个epoch保存一次权重# yapf:disablelog_config = dict( interval=50, # 每500个迭代就打印一次训练信息 hooks=[ dict(type='TextLoggerHook'), # dict(type='TensorboardLoggerHook') ])# yapf:enablecustom_hooks = [dict(type='NumClassCheckHook')]dist_params = dict(backend='nccl')log_level = 'INFO'load_from = None # 加载权重文件resume_from = Noneworkflow = [('train', 1)]# disable opencv multithreading to avoid system being overloadedopencv_num_threads = 0# set multi-process start method as `fork` to speed up the trainingmp_start_method = 'fork'# Default setting for scaling LR automatically# - `enable` means enable scaling LR automatically# or not by default.# - `base_batch_size` = (8 GPUs) x (2 samples per GPU).auto_scale_lr = dict(enable=False, base_batch_size=16)

一般不需要更改太多的内容,可以时代的更改log_config进行合理的打印训练信息,还有设置checkpoint_config进行合理的保存权重文件,其他的设置按默认即可。

下面展示我继承了default_runtime.py后更改的内容,其实就是更改了以上我所介绍的七点内容:

_base_ = [ '../_base_/default_runtime.py']......# optimizeroptimizer = dict( # 设置使用AdamW优化器(默认使用的是SGD) type='AdamW', lr=0.0001, weight_decay=0.0001, paramwise_cfg=dict(custom_keys={'backbone': dict(lr_mult=0.1, decay_mult=1.0)}))evaluation = dict(interval=5, metric='bbox') # 5个epoch验证一次optimizer_config = dict(grad_clip=dict(max_norm=0.1, norm_type=2)) # 设置梯度裁剪(default_runtime.py中默认为None)checkpoint_config = dict(interval=20) # 20个epoch保存一次权重log_config = dict(interval=50, # 每50次迭代训练就打印一次信息(注意是迭代而不是epoch) hooks=[dict(type='TextLoggerHook')])# learning policylr_config = dict(policy='step', step=[100]) # 学习率在100个epoch进行衰减runner = dict(type='EpochBasedRunner', max_epochs=150) # 训练150个epoch

参考资料:

1. Customize Runtime Settings

2. mmcv官方文档

本文链接地址:https://www.jiuchutong.com/zhishi/292341.html 转载请保留说明!

上一篇:【uniapp】页面下拉刷新(uniapp按钮)

下一篇:卡格拉格帝边境公园中一对正在求偶的鸵鸟,南非 (© Tina Malfilatre/Minden Pictures)(卡格拉河)

  • 微信朋友分类在哪里设置(微信朋友分类怎么分组)

    微信朋友分类在哪里设置(微信朋友分类怎么分组)

  • 苹果12可以更新15.3系统吗(苹果12可以更新17系统吗)

    苹果12可以更新15.3系统吗(苹果12可以更新17系统吗)

  • 苹果手机软件在哪里下载(苹果手机软件在哪里找)

    苹果手机软件在哪里下载(苹果手机软件在哪里找)

  • 腾讯课堂签到是否有记录(腾讯课堂签到是免费的吗)

    腾讯课堂签到是否有记录(腾讯课堂签到是免费的吗)

  • 华为电脑打不开了怎么办(华为电脑打不开文件怎么办)

    华为电脑打不开了怎么办(华为电脑打不开文件怎么办)

  • 骁龙439什么水平(骁龙439好不好)

    骁龙439什么水平(骁龙439好不好)

  • useradmin的密码是多少(useradmin的密码是wifi密码吗)

    useradmin的密码是多少(useradmin的密码是wifi密码吗)

  • VIVO连不上iphone11的热点(vivo连不上iphone11的热点)

    VIVO连不上iphone11的热点(vivo连不上iphone11的热点)

  • jbl音响怎么用(jbl音响怎么用蓝牙连接电脑)

    jbl音响怎么用(jbl音响怎么用蓝牙连接电脑)

  • 新买的手机卡被别人注册了怎么办(新买的手机卡被别人绑定了银行卡)

    新买的手机卡被别人注册了怎么办(新买的手机卡被别人绑定了银行卡)

  • 华为p40是直屏还是曲屏(华为p40是不是直屏)

    华为p40是直屏还是曲屏(华为p40是不是直屏)

  • 为什么苹果手机插了卡还是无服务(为什么苹果手机无线局域网打不开)

    为什么苹果手机插了卡还是无服务(为什么苹果手机无线局域网打不开)

  • uc网盘会员能收藏几次(uc网盘会员收藏次数)

    uc网盘会员能收藏几次(uc网盘会员收藏次数)

  • 微信语音黑屏设置方法(微信语音黑屏设置方法 为什么微信听语音会黑屏)

    微信语音黑屏设置方法(微信语音黑屏设置方法 为什么微信听语音会黑屏)

  • 一加7没法插耳机吗(一加7t插耳机没反应)

    一加7没法插耳机吗(一加7t插耳机没反应)

  • word怎么下载到电脑上(word怎么下载到u盘)

    word怎么下载到电脑上(word怎么下载到u盘)

  • 快手转盘抽奖在哪里(快手直播抽奖转盘怎么弄)

    快手转盘抽奖在哪里(快手直播抽奖转盘怎么弄)

  • 卡贴机不能打电话(卡贴机不能打电话能上网发短信是怎么回事)

    卡贴机不能打电话(卡贴机不能打电话能上网发短信是怎么回事)

  • 天猫精灵ccl怎么用(天猫精灵CCL怎么扩展内存)

    天猫精灵ccl怎么用(天猫精灵CCL怎么扩展内存)

  • 荣耀20支持18w快充吗(荣耀20支持多大快充)

    荣耀20支持18w快充吗(荣耀20支持多大快充)

  • 怎么把情侣黄钻标识去掉(怎么把情侣黄钻的装扮去掉)

    怎么把情侣黄钻标识去掉(怎么把情侣黄钻的装扮去掉)

  • 美颜相机下面的字母怎么去掉(美颜相机下面的水印如何去掉)

    美颜相机下面的字母怎么去掉(美颜相机下面的水印如何去掉)

  • airpods使用方法音量(airpods3使用方法)

    airpods使用方法音量(airpods3使用方法)

  • 抖音怎么调图片速度(抖音怎么调图片切换速度)

    抖音怎么调图片速度(抖音怎么调图片切换速度)

  • 出口退税免税有限额吗
  • 土地增值税与增值税
  • 购买税控盘分录怎么做
  • 小规模企业增值税减免政策
  • 增值税税率调整为9%
  • 开票系统技术服务费在申报表哪里抵扣
  • 建筑企业怎么转让
  • 外贸企业出口采购流程
  • 发票大头小尾什么意思
  • 利息保障倍数为负数,是偿债能力弱的表现
  • 房地产企业用电计入什么科目
  • 计提利息怎么做账
  • 给政府开发票如何处理?
  • 企业股权转让有什么好处
  • 饭店取得的烟酒是什么
  • 员工疗养要扣公休假吗
  • 为什么查询发票显示查无此票
  • 促销活动赠品应如何账务处理
  • 商业健康保险个税申报
  • 税务行业软件
  • 总资产周转率多少算高
  • 铁路改道作业的流程
  • 新公司会计建账流程
  • 员工奖励专项基金怎么填
  • 跨年度的暂估入库账务处理
  • 个人所得汇算清缴是什么
  • 周转材料月末有余额吗
  • 运杂费计入什么科目
  • 直接人工分配按计时工资怎么分
  • 银行进账单是银行开吗
  • framework启动
  • multipartfile 多文件上传
  • 可供出售和交易性金融资产的区别
  • php file_get_contents smb
  • lvs安装配置
  • idea 创建maven项目读取pom报错
  • 简述php操作mysql数据库的基本步骤
  • phpstudy ftp怎么用
  • 关于高德地图的分析报告
  • 个税的本期收入是什么意思
  • 跨年的增值税专票怎么开
  • 企业税金总额包括什么
  • 售价金额核算法的优点有
  • 报表中的盈余公积怎么算
  • 代扣代缴个人所得税分录
  • 所得税汇算清缴前取得跨年发票
  • 两个公司可以是一个注册地址吗
  • 写字楼租金
  • 一般纳税人条件要求2020
  • 如何确定交易性金融资金
  • 赠送的商品如何开发票
  • 原材料跌价分录
  • 支付宝可以对公账户转账吗怎么转
  • 退货回去需要把原包装保留吗
  • 计提待摊费用分录
  • 员工垫付的费用会计分录
  • 销售额营业收入是指一年还是一个月
  • 公司名义送花篮属于什么费用
  • 新准则下企业开什么发票
  • 一般纳税人增值税优惠政策2023
  • 外资房地产企业 利润汇出比例
  • 怎么使用winpe
  • linux常见压缩工具
  • 微信小程序支付的钱怎么退款
  • firefox和谷歌
  • python安装pip.whl
  • angular scope
  • [置顶]津鱼.我爱你
  • javascript+
  • js中的!
  • javascript 继承
  • 彻底解决老鼠进发动机舱
  • jquery常用操作
  • 用javascript
  • 河南省国家税务局通用定额发票
  • 重庆市国家税务局电子税务局官网
  • 乌市沙区医保局电话是多少
  • 查询发票号码
  • 个体如何申请税收优惠
  • 印花税属于什么业务类型
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设