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

[Feature] Support TTA #9452

Merged
merged 22 commits into from
Feb 14, 2023
Merged

[Feature] Support TTA #9452

merged 22 commits into from
Feb 14, 2023

Conversation

zytx121
Copy link
Collaborator

@zytx121 zytx121 commented Dec 6, 2022

open-mmlab/mmengine#611 is required.

Motivation

To support Test-Time-Aug (TTA).

Modification

  • Add DetTTAModel inherited from the BaseTTAModel in MMEngine.
  • Add --tta option in tools/test.py to enable TTA during the test.

Use cases

To use the default TTA (average the classification scores of images w/ and w/o flip)

 python tools/test.py configs/retinanet/retinanet_r50_fpn_1x_coco.py checkpoints/resnet50_coco.pth --tta

To use your own custom TTA method

  1. Add tta_model and tta_pipeline in your config file:
tta_model = dict(
   type='DetTTAModel',
   tta_cfg=dict(nms=dict(type='nms', iou_threshold=0.5), max_per_img=100))
tta_pipeline = [
       dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),
       dict(type='TestTimeAug',
            transforms=[
                [dict(type='Resize', scale=(1333, 800), keep_ratio=True),
                 dict(type='Resize', scale=(1333, 600), keep_ratio=True)],
                [dict(type='RandomFlip', prob=1.),
                 dict(type='RandomFlip', prob=0.)],
                [dict(type='LoadAnnotations', with_bbox=True)],
                [dict(type='PackDetInputs',
                      meta_keys=('img_id', 'img_path', 'ori_shape',
                                 'img_shape', 'scale_factor', 'flip',
                                 'flip_direction'))]])
   ]
  1. test with TTA
python tools/test.py configs/retinanet/retinanet_r50_fpn_1x_coco.py checkpoints.pth --tta

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.

@zytx121 zytx121 added the WIP Working in progress label Dec 6, 2022
tools/test.py Outdated Show resolved Hide resolved
configs/_base_/models/retinanet_r50_fpn.py Outdated Show resolved Hide resolved
configs/_base_/models/retinanet_r50_fpn.py Outdated Show resolved Hide resolved
mmdet/models/test_time_augs/det_tta.py Outdated Show resolved Hide resolved
mmdet/models/test_time_augs/det_tta.py Outdated Show resolved Hide resolved
mmdet/models/test_time_augs/det_tta.py Outdated Show resolved Hide resolved
mmdet/models/test_time_augs/det_tta.py Outdated Show resolved Hide resolved
mmdet/models/test_time_augs/det_tta.py Show resolved Hide resolved
Copy link
Member

@RangiLyu RangiLyu left a comment

Choose a reason for hiding this comment

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

Remember to update the document of TTA after the usage is confirmed.

@hhaAndroid
Copy link
Collaborator

@zytx121 Please synchronize the latest code to ensure that ci can pass

configs/_base_/models/retinanet_r50_fpn.py Outdated Show resolved Hide resolved
tools/test.py Outdated Show resolved Hide resolved
@zytx121
Copy link
Collaborator Author

zytx121 commented Feb 5, 2023

@zytx121 Please synchronize the latest code to ensure that ci can pass

Done.

@zytx121 zytx121 requested a review from RangiLyu February 8, 2023 11:15
RangiLyu
RangiLyu previously approved these changes Feb 8, 2023
Copy link
Member

@RangiLyu RangiLyu left a comment

Choose a reason for hiding this comment

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

LGTM. It would be better if you can add a warning in test.py if there is no tta_cfg in the config.

@RangiLyu
Copy link
Member

RangiLyu commented Feb 8, 2023

Add the use case to docs/en/user_guides/test.md

@zytx121
Copy link
Collaborator Author

zytx121 commented Feb 8, 2023

Add the use case to docs/en/user_guides/test.md

LGTM. It would be better if you can add a warning in test.py if there is no tta_cfg in the config.

Done.

RangiLyu
RangiLyu previously approved these changes Feb 9, 2023
hhaAndroid
hhaAndroid previously approved these changes Feb 9, 2023
docs/en/user_guides/test.md Outdated Show resolved Hide resolved
docs/en/user_guides/test.md Outdated Show resolved Hide resolved
docs/en/user_guides/test.md Outdated Show resolved Hide resolved
Co-authored-by: Wenwei Zhang <40779233+ZwwWayne@users.noreply.github.com>
@ZwwWayne ZwwWayne merged commit 99e02c7 into open-mmlab:dev-3.x Feb 14, 2023
yumion pushed a commit to yumion/mmdetection that referenced this pull request Jan 31, 2024
…mlab#9452)

Co-authored-by: RangiLyu <lyuchqi@gmail.com>
Co-authored-by: Wenwei Zhang <40779233+ZwwWayne@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants