mmdet 1: Learn about Configs
TUTORIAL 1: LEARN ABOUT CONFIGS
config파일은 모듈화되어 있어 여러 config 조각을 합쳐서 사용한다.
완성된 하나의 config 파일 보고 싶다면, python tools/misc/print_config.py /PATH/TO/CONFIG
를 활용한다.
명령창에서 스크립트의 argument를 통해 config 수정
Read More…When submitting jobs using “tools/train.py” or “tools/test.py”,
you may specify --cfg-options
to in-place modify the config.
- dict chains의 (config) key를 업데이트.
Update config keys of dict chains.
The config options can be specified following the order of the dict keys in the original config.
예>--cfg-options model.backbone.norm_eval=False
changes the all BN modules in model backbones totrain
mode. - config파일(config의 List)내에서 key 업데이트
Update keys inside a list of configs.
Some config dicts are composed as a list in your config.
예> the training pipelinedata.train.pipeline
is normally a list
e.g.[dict(type='LoadImageFromFile'), ...]
.
If you want to change'LoadImageFromFile'
to'LoadImageFromWebcam'
in the pipeline,
you may specify--cfg-options data.train.pipeline.0.type=LoadImageFromWebcam
.
- Update values of list/tuples. If the value to be updated is a list or a tuple.
예> the config file normally setsworkflow=[('train', 1)]
.
If you want to change this key, you may specify--cfg-options workflow="[(train,1),(val,1)]"
.
Note that the quotation mark ” is necessary to support list/tuple data types, and that NO white space is allowed inside the quotation marks in the specified value.
Config File 구조
config/_base_
, 아래 4개의 기본 component 타입으로 이뤄져 있음.
- dataset
- model
- schedule
- default_runtime.
Many methods could be easily constructed with one of each like Faster R-CNN, Mask R-CNN, Cascade R-CNN, RPN, SSD.
The configs that are composed by components from _base_
are called primitive.
For all configs under the same folder, it is recommended to have only one primitive config.
All other configs should inherit from the primitive config. In this way, the maximum of inheritance level is 3.
For easy understanding, we recommend contributors to inherit from existing methods.
예> if some modification is made base on Faster R-CNN, user may first inherit the basic Faster R-CNN structure by specifying _base_ = ../faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py
, then modify the necessary fields in the config files.
If you are building an entirely new method that does not share the structure with any of the existing methods, you may create a folder xxx_rcnn
under configs
,
Please refer to mmcv for detailed documentation.
Config Name Style
We follow the below style to name config files. Contributors are advised to follow the same style.
{model}_[model setting]_ {backbone}_{neck}_[norm setting]_[misc]_[gpu x batch_per_gpu]_{schedule}_{dataset}
{model}_[model setting]_ {backbone}_ {neck}_[norm setting]_[misc]_[gpu x batch_per_gpu]_ {schedule}_ {dataset}
{xxx}
is required field and [yyy]
is optional.
{model}
: model type likefaster_rcnn
,mask_rcnn
, etc.[model setting]
: specific setting for some model, likewithout_semantic
forhtc
,moment
forreppoints
, etc.{backbone}
: backbone type liker50
(ResNet-50),x101
(ResNeXt-101).{neck}
: neck type likefpn
,pafpn
,nasfpn
,c4
.[norm_setting]
:bn
(Batch Normalization) is used unless specified,gn
(Group Normalization),syncbn
(Synchronized Batch Normalization).gn-head
/gn-neck
indicates GN is applied in head/neck only, whilegn-all
means GN is applied in the entire model, e.g. backbone, neck, head.[misc]
: miscellaneous setting/plugins of model, e.g.dconv
,gcb
,attention
,albu
,mstrain
.[gpu x batch_per_gpu]
: GPUs and samples per GPU,8x2
is used by default.{schedule}
: training schedule, options are1x
,2x
,20e
, etc.1x
and2x
means 12 epochs and 24 epochs respectively.20e
is adopted in cascade models, which denotes 20 epochs.
For1x
/2x
, initial learning rate decays by a factor of 10 at the 8/16th and 11/22th epochs. For20e
, initial learning rate decays by a factor of 10 at the 16th and 19th epochs.{dataset}
: dataset likecoco
,cityscapes
,voc_0712
,wider_face
.
예)
faster_rcnn_r50_fpn_1x_coco
- model : faster_rcnn
- backbone : ResNet 50
- neck : fpn
- schedule : 1x (12 epochs)
- dataset : coco
cascade_mask_rcnn_convnext-s_p4_w7_fpn_giou_4conv1f_fp16_ms-crop_3x_coco
- model : cascade_mask_rcnn
- backbone : convnext-s (small)
- : p4_w7
- neck : fpn
misc
: giou_4conv1f_fp16_ms-crop- schedule : 3x (36 epochs)
- dataset : coco
Deprecated train_cfg/test_cfg
Read More…The train_cfg
and test_cfg
are deprecated in config file, please specify them in the model config.
The original config structure is as below.
# deprecated model = dict( type=..., ... ) train_cfg=dict(...) test_cfg=dict(...)
The migration example is as below.
# recommended model = dict( type=..., ... train_cfg=dict(...), test_cfg=dict(...), )
An Example of Mask R-CNN
To help the users have a basic idea of a complete config and the modules in a modern detection system, we make brief comments on the config of Mask R-CNN using ResNet50 and FPN as the following.
For more detailed usage and the corresponding alternative for each modules, please refer to the API documentation.
FAQ
Ignore some fields in the base configs
Sometimes, you may set _delete_=True
to ignore some of fields in base configs.
You may refer to mmcv for simple illustration.
In MMDetection, for example, to change the backbone of Mask R-CNN with the following config.
model = dict( type='MaskRCNN', pretrained='torchvision://resnet50', backbone=dict( type='ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=1, norm_cfg=dict(type='BN', requires_grad=True), norm_eval=True, style='pytorch'), neck=dict(...), rpn_head=dict(...), roi_head=dict(...))
ResNet
and HRNet
use different keywords to construct.
_base_ = '../mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py' model = dict( pretrained='open-mmlab://msra/hrnetv2_w32', backbone=dict( _delete_=True, type='HRNet', extra=dict( stage1=dict( num_modules=1, num_branches=1, block='BOTTLENECK', num_blocks=(4, ), num_channels=(64, )), stage2=dict( num_modules=1, num_branches=2, block='BASIC', num_blocks=(4, 4), num_channels=(32, 64)), stage3=dict( num_modules=4, num_branches=3, block='BASIC', num_blocks=(4, 4, 4), num_channels=(32, 64, 128)), stage4=dict( num_modules=3, num_branches=4, block='BASIC', num_blocks=(4, 4, 4, 4), num_channels=(32, 64, 128, 256)))), neck=dict(...))
The _delete_=True
would replace all old keys in backbone
field with new keys.
Use intermediate variables in configs
Some intermediate variables are used in the configs files, like train_pipeline
/test_pipeline
in datasets. It’s worth noting that when modifying intermediate variables in the children configs, user need to pass the intermediate variables into corresponding fields again. For example, we would like to use multi scale strategy to train a Mask R-CNN. train_pipeline
/test_pipeline
are intermediate variable we would like modify.
_base_ = './mask_rcnn_r50_fpn_1x_coco.py' img_norm_cfg = dict( mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True, with_mask=True), dict( type='Resize', img_scale=[(1333, 640), (1333, 672), (1333, 704), (1333, 736), (1333, 768), (1333, 800)], multiscale_mode="value", keep_ratio=True), dict(type='RandomFlip', flip_ratio=0.5), dict(type='Normalize', **img_norm_cfg), dict(type='Pad', size_divisor=32), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks']), ] test_pipeline = [ dict(type='LoadImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=(1333, 800), flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='Normalize', **img_norm_cfg), dict(type='Pad', size_divisor=32), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']), ]) ] data = dict( train=dict(pipeline=train_pipeline), val=dict(pipeline=test_pipeline), test=dict(pipeline=test_pipeline))
We first define the new train_pipeline
/test_pipeline
and pass them into data
.
Similarly, if we would like to switch from SyncBN
to BN
or MMSyncBN
, we need to substitute every norm_cfg
in the config.
_base_ = './mask_rcnn_r50_fpn_1x_coco.py' norm_cfg = dict(type='BN', requires_grad=True) model = dict( backbone=dict(norm_cfg=norm_cfg), neck=dict(norm_cfg=norm_cfg), ...)