From 75997fcd601cbf09dbf0e546f084d91f508bffe2 Mon Sep 17 00:00:00 2001 From: Range King <RangeKingHZ@gmail.com> Date: Sun, 23 Oct 2022 10:53:49 +0800 Subject: [PATCH] [Docs] Refine config.md (#191) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refine __delete__ example in config.md * Add missing docstring in cspnext.py * Refine docstring of cspnext * Correct the description of param_scheduler * Refine description param_scheduler in config.md * Update docs/zh_cn/user_guides/config.md Co-authored-by: Haian Huang(深度眸) <1286304229@qq.com> Co-authored-by: Haian Huang(深度眸) <1286304229@qq.com> --- docs/en/user_guides/config.md | 15 +++++++++------ docs/zh_cn/user_guides/config.md | 15 +++++++++------ mmyolo/models/backbones/cspnext.py | 5 +++-- mmyolo/models/necks/cspnext_pafpn.py | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/en/user_guides/config.md b/docs/en/user_guides/config.md index 0800d144..56edadf5 100644 --- a/docs/en/user_guides/config.md +++ b/docs/en/user_guides/config.md @@ -286,7 +286,7 @@ optim_wrapper = dict( # Optimizer wrapper config constructor='YOLOv5OptimizerConstructor') # The constructor for YOLOv5 optimizer ``` -`param_scheduler` is the field that configures methods of adjusting optimization hyperparameters such as learning rate and momentum. Users can combine multiple schedulers to create a desired parameter adjustment strategy. Find more in the [parameter scheduler tutorial](https://mmengine.readthedocs.io/en/latest/tutorials/param_scheduler.html). In MMYOLO, no parameter optimizer is introduced. +`param_scheduler` is the field that configures methods of adjusting optimization hyperparameters such as learning rate and momentum. Users can combine multiple schedulers to create a desired parameter adjustment strategy. Find more in the [parameter scheduler tutorial](https://mmengine.readthedocs.io/en/latest/tutorials/param_scheduler.html). In YOLOv5, parameter scheduling is complex to implement and difficult to implement with `param_scheduler`. So we use `YOLOv5ParamSchedulerHook` to implement it (see next section), which is simpler but less versatile. ```python param_scheduler = None @@ -387,26 +387,29 @@ If you wish to inspect the config file, you may run `mim run mmdet print_config Sometimes, you may set `_delete_=True` to ignore some of the fields in base configs. You may refer to the [mmengine config tutorial](https://mmengine.readthedocs.io/en/latest/tutorials/config.html) for a simple illustration. -In MMYOLO, for example, to change the backbone of YOLOv5 with the following config. +In MMYOLO, for example, to change the backbone of RTMDet with the following config. ```python model = dict( type='YOLODetector', data_preprocessor=dict(...), backbone=dict( - type='YOLOv5CSPDarknet', + type='CSPNeXt', + arch='P5', + expand_ratio=0.5, deepen_factor=deepen_factor, widen_factor=widen_factor, - norm_cfg=dict(type='BN', momentum=0.03, eps=0.001), + channel_attention=True, + norm_cfg=dict(type='BN'), act_cfg=dict(type='SiLU', inplace=True)), neck=dict(...), bbox_head=dict(...)) ``` -The `_delete_=True` would replace all old keys in the `backbone` field with new keys. For example, `YOLOv5` uses `YOLOv5CSPDarknet`, it is necessary to replace the backbone with `YOLOv6EfficientRep`. Since `YOLOv5CSPDarknet` and `YOLOv6EfficientRep` have different fields, you need to use `_delete_=True` to replace all old keys in the `backbone` field. +If you want to change `CSPNeXt` to `YOLOv6EfficientRep` for the RTMDet backbone, because there are different fields (`channel_attention` and `expand_ratio`) in `CSPNeXt` and `YOLOv6EfficientRep`, you need to use `_delete_=True` to replace all the old keys in the `backbone` field with the new keys. ```python -_base_ = '../yolov5/yolov5_s-v61_syncbn_8xb16-300e_coco.py' +_base_ = '../rtmdet/rtmdet_l_syncbn_8xb32-300e_coco.py' model = dict( backbone=dict( _delete_=True, diff --git a/docs/zh_cn/user_guides/config.md b/docs/zh_cn/user_guides/config.md index 17b64a6c..355ef5d1 100644 --- a/docs/zh_cn/user_guides/config.md +++ b/docs/zh_cn/user_guides/config.md @@ -287,7 +287,7 @@ optim_wrapper = dict( # 优化器封装的配置 ``` -`param_scheduler` 字段用于配置参数调度器(Parameter Scheduler)来调整优化器的超参数(例如学习率和动量)。 用户可以组合多个调度器来创建所需的参数调整策略。 在[参数调度器教程](https://mmengine.readthedocs.io/zh_CN/latest/tutorials/param_scheduler.html) 和参数调度器 API 文档 中查找更多信息。在 MMYOLO 中,未引入任何参数调度器。 +`param_scheduler` 字段用于配置参数调度器(Parameter Scheduler)来调整优化器的超参数(例如学习率和动量)。 用户可以组合多个调度器来创建所需的参数调整策略。 在[参数调度器教程](https://mmengine.readthedocs.io/zh_CN/latest/tutorials/param_scheduler.html) 和参数调度器 API 文档 中查找更多信息。在 YOLOv5 中,参数调度实现比较复杂,难以通过 `param_scheduler` 实现。所以我们采用了 `YOLOv5ParamSchedulerHook` 来实现(见下节),这样做更简单但是通用性较差。 ```python param_scheduler = None @@ -386,26 +386,29 @@ _base_ = [ 有时,您也许会设置 `_delete_=True` 去忽略基础配置文件里的一些域内容。 您也许可以参照 [MMEngine 配置文件教程](https://mmengine.readthedocs.io/en/latest/tutorials/config.html) 来获得一些简单的指导。 -在 MMYOLO 里,例如为了改变 YOLOv5 的主干网络的某些内容: +在 MMYOLO 里,例如为了改变 RTMDet 的主干网络的某些内容: ```python model = dict( type='YOLODetector', data_preprocessor=dict(...), backbone=dict( - type='YOLOv5CSPDarknet', + type='CSPNeXt', + arch='P5', + expand_ratio=0.5, deepen_factor=deepen_factor, widen_factor=widen_factor, - norm_cfg=dict(type='BN', momentum=0.03, eps=0.001), + channel_attention=True, + norm_cfg=dict(type='BN'), act_cfg=dict(type='SiLU', inplace=True)), neck=dict(...), bbox_head=dict(...)) ``` -基础配置的 `YOLOv5` 使用 `YOLOv5CSPDarknet`,在需要将主干网络改成 `YOLOv6EfficientRep` 的时候,因为 `YOLOv5CSPDarknet` 和 `YOLOv6EfficientRep` 中有不同的字段,需要使用 `_delete_=True` 将新的键去替换 `backbone` 域内所有老的键。 +如果想把 RTMDet 主干网络的 `CSPNeXt` 改成 `YOLOv6EfficientRep`,因为 `CSPNeXt` 和 `YOLOv6EfficientRep` 中有不同的字段(`channel_attention` 和 `expand_ratio`),这时候就需要使用 `_delete_=True` 将新的键去替换 `backbone` 域内所有老的键。 ```python -_base_ = '../yolov5/yolov5_s-v61_syncbn_8xb16-300e_coco.py' +_base_ = '../rtmdet/rtmdet_l_syncbn_8xb32-300e_coco.py' model = dict( backbone=dict( _delete_=True, diff --git a/mmyolo/models/backbones/cspnext.py b/mmyolo/models/backbones/cspnext.py index 2ef0c896..f12e37a4 100644 --- a/mmyolo/models/backbones/cspnext.py +++ b/mmyolo/models/backbones/cspnext.py @@ -28,12 +28,13 @@ class CSPNeXt(BaseBackbone): frozen_stages (int): Stages to be frozen (stop grad and set eval mode). -1 means not freezing any parameters. Defaults to -1. plugins (list[dict]): List of plugins for stages, each dict contains: - - - cfg (dict, required): Cfg dict to build plugin. + - cfg (dict, required): Cfg dict to build plugin.Defaults to - stages (tuple[bool], optional): Stages to apply plugin, length should be same as 'num_stages'. use_depthwise (bool): Whether to use depthwise separable convolution. Defaults to False. + expand_ratio (float): Ratio to adjust the number of channels of the + hidden layer. Defaults to 0.5. arch_ovewrite (list): Overwrite default arch settings. Defaults to None. channel_attention (bool): Whether to add channel attention in each diff --git a/mmyolo/models/necks/cspnext_pafpn.py b/mmyolo/models/necks/cspnext_pafpn.py index 710d85dd..a4dc846e 100644 --- a/mmyolo/models/necks/cspnext_pafpn.py +++ b/mmyolo/models/necks/cspnext_pafpn.py @@ -27,7 +27,7 @@ class CSPNeXtPAFPN(BaseYOLONeck): use_depthwise (bool): Whether to use depthwise separable convolution in blocks. Defaults to False. expand_ratio (float): Ratio to adjust the number of channels of the - hidden layer. Default: 0.5 + hidden layer. Defaults to 0.5. upsample_cfg (dict): Config dict for interpolate layer. Default: `dict(scale_factor=2, mode='nearest')` conv_cfg (dict, optional): Config dict for convolution layer.