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] Rec TTA #1401

Merged
merged 4 commits into from
Feb 16, 2023
Merged

[Feature] Rec TTA #1401

merged 4 commits into from
Feb 16, 2023

Conversation

Harold-lkk
Copy link
Collaborator

@Harold-lkk Harold-lkk commented Sep 21, 2022

open-mmlab/mmengine#611 is required.

Motivation

To support Test-Time-Aug (TTA).

Modification

  • Add EncoderDecoderRecognizerTTAModel 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

 python tools/test.py configs/textrecog/crnn/crnn_mini-vgg_5e_mj.py checkpoints/crnn_mini-vgg_5e_mj.pth --tta

To use your own custom TTA method

  1. Add tta_model and tta_pipeline in your config file:
tta_model = dict(
   type='EncoderDecoderRecognizerTTAModel')

tta_pipeline = [
   dict(
       type='LoadImageFromFile',
       color_type='grayscale',
       file_client_args=file_client_args),
   dict(
       type='TestTimeAug',
       transforms=[
           [
               dict(
                   type='ConditionApply',
                   true_transforms=[
                       dict(
                           type='ImgAugWrapper',
                           args=[dict(cls='Rot90', k=0, keep_size=False)])
                   ],
                   condition="results['img_shape'][1]<results['img_shape'][0]"
               ),
               dict(
                   type='ConditionApply',
                   true_transforms=[
                       dict(
                           type='ImgAugWrapper',
                           args=[dict(cls='Rot90', k=1, keep_size=False)])
                   ],
                   condition="results['img_shape'][1]<results['img_shape'][0]"
               ),
               dict(
                   type='ConditionApply',
                   true_transforms=[
                       dict(
                           type='ImgAugWrapper',
                           args=[dict(cls='Rot90', k=3, keep_size=False)])
                   ],
                   condition="results['img_shape'][1]<results['img_shape'][0]"
               ),
           ],
           [
               dict(
                   type='RescaleToHeight',
                   height=32,
                   min_width=32,
                   max_width=None,
                   width_divisor=16)
           ],
           # add loading annotation after ``Resize`` because ground truth
           # does not need to do resize data transform
           [dict(type='LoadOCRAnnotations', with_text=True)],
           [
               dict(
                   type='PackTextRecogInputs',
                   meta_keys=('img_path', 'ori_shape', 'img_shape',
                              'valid_ratio'))
           ]
       ])
]
  1. test with TTA
python tools/test.py configs/textrecog/crnn/crnn.py checkpoints/crnn.pth --tta

@CLAassistant
Copy link

CLAassistant commented Oct 30, 2022

CLA assistant check
All committers have signed the CLA.

@Harold-lkk Harold-lkk marked this pull request as ready for review February 13, 2023 09:17
@Harold-lkk Harold-lkk changed the title [Draft] Rec TTA [Feature] Rec TTA Feb 13, 2023
@Harold-lkk Harold-lkk assigned gaotongxiao and unassigned xinke-wang Feb 13, 2023
@codecov
Copy link

codecov bot commented Feb 14, 2023

Codecov Report

Base: 88.32% // Head: 88.32% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (0cf1efa) compared to base (edf085c).
Patch coverage: 89.65% of modified lines in pull request are covered.

❗ Current head 0cf1efa differs from pull request most recent head f021ca2. Consider uploading reports for the commit f021ca2 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           dev-1.x    #1401      +/-   ##
===========================================
- Coverage    88.32%   88.32%   -0.01%     
===========================================
  Files          175      176       +1     
  Lines        10896    10919      +23     
  Branches      1527     1533       +6     
===========================================
+ Hits          9624     9644      +20     
- Misses         992      993       +1     
- Partials       280      282       +2     
Flag Coverage Δ
unittests 88.32% <89.65%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
mmocr/datasets/preparers/parsers/coco_parser.py 17.30% <0.00%> (-0.34%) ⬇️
mmocr/ocr.py 0.00% <ø> (ø)
mmocr/apis/inferencers/kie_inferencer.py 81.48% <60.00%> (-0.43%) ⬇️
mmocr/apis/inferencers/base_mmocr_inferencer.py 89.36% <100.00%> (-1.07%) ⬇️
mmocr/models/textrecog/decoders/aster_decoder.py 100.00% <100.00%> (ø)
...ecog/recognizers/encoder_decoder_recognizer_tta.py 100.00% <100.00%> (ø)
mmocr/utils/polygon_utils.py 97.54% <100.00%> (+0.04%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

configs/textrecog/crnn/README.md Outdated Show resolved Hide resolved
tools/test.py Outdated Show resolved Hide resolved
@gaotongxiao
Copy link
Collaborator

Also update the documentation

@gaotongxiao gaotongxiao merged commit f820470 into open-mmlab:dev-1.x Feb 16, 2023
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