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

[Tools] Support replacing the ${key} with the value of cfg.key #7492

Merged
merged 22 commits into from
May 11, 2022

Conversation

Czm369
Copy link
Collaborator

@Czm369 Czm369 commented Mar 22, 2022

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Replace the ${key} with the value of ori_cfg.key in the config. And support replacing the chained ${key}. Such as, replace ${key0.key1} with the value of cfg.key0.key1.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

The origin config with "${key}":

ori_cfg_dict = dict()
ori_cfg_dict['work_dir'] = 'work_dirs/${percent}/${fold}'
ori_cfg_dict['percent'] = 5
ori_cfg_dict['fold'] = 1
ori_cfg_dict['model_wrapper'] = dict(type='SoftTeacher', detector='${model}')
ori_cfg_dict['model'] = dict(
        type='FasterRCNN',
        backbone=dict(type='ResNet'),
        neck=dict(type='FPN'),
        rpn_head=dict(type='RPNHead'),
        roi_head=dict(type='StandardRoIHead'),
        train_cfg=dict(
            rpn=dict(
                assigner=dict(type='MaxIoUAssigner'),
                sampler=dict(type='RandomSampler'),
            ),
            rpn_proposal=dict(nms=dict(type='nms', iou_threshold=0.7)),
            rcnn=dict(
                assigner=dict(type='MaxIoUAssigner'),
                sampler=dict(type='RandomSampler'),
            ),
        ),
        test_cfg=dict(
            rpn=dict(nms=dict(type='nms', iou_threshold=0.7)),
            rcnn=dict(nms=dict(type='nms', iou_threshold=0.5)),
        ),
    )
ori_cfg_dict['iou_threshold'] = dict(
        rpn_proposal_nms='${model.train_cfg.rpn_proposal.nms.iou_threshold}',
        test_rpn_nms='${model.test_cfg.rpn.nms.iou_threshold}',
        test_rcnn_nms='${model.test_cfg.rcnn.nms.iou_threshold}',
    )
ori_cfg_dict['a'] = 'xxxxx${b}xxxxx'
ori_cfg_dict['b'] = 'Hello, world!'
ori_cfg = Config(ori_cfg_dict, filename=cfg_path)

After replacing the ${key} with the corresponding value.

updated_cfg = replace_cfg_vals(deepcopy(ori_cfg))

The updated_cfg satisfies that

updated_cfg.work_dir ==  'work_dirs/5/1'
updated_cfg.model.detector == ori_cfg.model
updated_cfg.iou_threshold.rpn_proposal_nms == ori_cfg.model.train_cfg.rpn_proposal.nms.iou_threshold
updated_cfg.a  == 'xxxxxHello, world!xxxxx'

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@mm-assistant mm-assistant bot added the size/XS label Mar 22, 2022
mmdet/utils/replace.py Outdated Show resolved Hide resolved
mmdet/utils/replace.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 22, 2022

Codecov Report

Merging #7492 (5c1a503) into dev (b1f40ef) will increase coverage by 0.01%.
The diff coverage is 96.77%.

@@            Coverage Diff             @@
##              dev    #7492      +/-   ##
==========================================
+ Coverage   64.89%   64.90%   +0.01%     
==========================================
  Files         351      352       +1     
  Lines       28466    28497      +31     
  Branches     4807     4819      +12     
==========================================
+ Hits        18472    18495      +23     
- Misses       9014     9024      +10     
+ Partials      980      978       -2     
Flag Coverage Δ
unittests 64.87% <96.77%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmdet/utils/replace_cfg_vals.py 96.66% <96.66%> (ø)
mmdet/utils/__init__.py 100.00% <100.00%> (ø)
mmdet/models/detectors/cornernet.py 94.87% <0.00%> (-5.13%) ⬇️
mmdet/models/dense_heads/corner_head.py 68.33% <0.00%> (-1.39%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1f40ef...5c1a503. Read the comment docs.

@Czm369 Czm369 changed the title [Feature] Support replacing the ${key} with the value of cfg.key [Tools] Support replacing the ${key} with the value of cfg.key Mar 30, 2022
@Czm369 Czm369 requested a review from hhaAndroid March 30, 2022 09:54
mmdet/utils/replace.py Outdated Show resolved Hide resolved
mmdet/utils/replace.py Outdated Show resolved Hide resolved
mmdet/utils/replace.py Outdated Show resolved Hide resolved
mmdet/utils/replace.py Outdated Show resolved Hide resolved
mmdet/utils/__init__.py Outdated Show resolved Hide resolved
mmdet/utils/replace.py Outdated Show resolved Hide resolved
mmdet/utils/replace.py Outdated Show resolved Hide resolved
mmdet/utils/replace_cfg_vals.py Show resolved Hide resolved
tools/train.py Outdated Show resolved Hide resolved
mmdet/utils/replace_cfg_vals.py Outdated Show resolved Hide resolved
@open-mmlab open-mmlab deleted a comment from hhaAndroid Apr 22, 2022
Copy link
Collaborator

@hhaAndroid hhaAndroid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ZwwWayne ZwwWayne merged commit 0db1b9b into open-mmlab:dev May 11, 2022
ZwwWayne pushed a commit that referenced this pull request Jul 18, 2022
* Support replacing config

* Support replacing config

* Add unit test for replace_cfig

* pre-commit

* fix

* modify the docstring

* rename function

* fix a bug

* fix a bug and simplify the code

* simplify the code

* add replace_cfg_vals for some scripts

* add replace_cfg_vals for some scripts

* add some unit tests
ZwwWayne pushed a commit to ZwwWayne/mmdetection that referenced this pull request Jul 19, 2022
…mmlab#7492)

* Support replacing config

* Support replacing config

* Add unit test for replace_cfig

* pre-commit

* fix

* modify the docstring

* rename function

* fix a bug

* fix a bug and simplify the code

* simplify the code

* add replace_cfg_vals for some scripts

* add replace_cfg_vals for some scripts

* add some unit tests
ZwwWayne pushed a commit to ZwwWayne/mmdetection that referenced this pull request Jul 19, 2022
…mmlab#7492)

* Support replacing config

* Support replacing config

* Add unit test for replace_cfig

* pre-commit

* fix

* modify the docstring

* rename function

* fix a bug

* fix a bug and simplify the code

* simplify the code

* add replace_cfg_vals for some scripts

* add replace_cfg_vals for some scripts

* add some unit tests
@Czm369 Czm369 deleted the replace_config branch August 20, 2022 12:36
SakiRinn pushed a commit to SakiRinn/mmdetection-locount that referenced this pull request Mar 17, 2023
…mmlab#7492)

* Support replacing config

* Support replacing config

* Add unit test for replace_cfig

* pre-commit

* fix

* modify the docstring

* rename function

* fix a bug

* fix a bug and simplify the code

* simplify the code

* add replace_cfg_vals for some scripts

* add replace_cfg_vals for some scripts

* add some unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants