Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Refine config.md #191

Merged
merged 6 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions docs/en/user_guides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 9 additions & 6 deletions docs/zh_cn/user_guides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions mmyolo/models/backbones/cspnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mmyolo/models/necks/cspnext_pafpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down