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] Add Switch Recipe Hook #1101

Merged
merged 15 commits into from
Nov 18, 2022

Conversation

Ezra-Yu
Copy link
Collaborator

@Ezra-Yu Ezra-Yu commented Oct 18, 2022

Motivation

Add Switch Recipe Hook

some papers could use this hook:
efficientnetv2
mobileone
Data Augmentation Revisited: Rethinking the Distribution Gap between Clean and Augmented Data

Modification

This PR is migrated from #729 of 0.x branch.

Use cases (Optional)

 base_train_pipeline = [                                                                                                                                                                           
     dict(type='LoadImageFromFile'),                                                                                                                                                               
     dict(type='RandomResizedCrop', scale=224, backend='pillow'),                                                                                                                                  
     dict(type='RandomFlip', prob=0.5, direction='horizontal'),                                                                                                                                    
     dict(type='PackClsInputs')                                                                                                                                                                    
 ]                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
 import copy                                                                                                                                                                                       
 # modify 37 epoch's RandomResizedCrop.scale to 192                                                                                                                                                 
 train_pipeline_37e = copy.deepcopy(base_train_pipeline)                                                                                                                                           
 train_pipeline_37e[1]['scale'] = 192                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                               
 custom_hooks = [                                                                                                                                                                                  
     dict(                                                                                                                                                                                         
         type='SwitchRecipeHook',                                                                                                                                                                 
         schedule=[
             dict(
                 action_epoch=30,
                 train_pipeline=pipeline_after_37e,
                 batch_augments=batch_augments_after_37e,
                 loss=loss_after_37e,),
             dict(
                 action_epoch=60,
                 # Disable batch augmentations after 112e
                 # and keep other settings.
                 batch_augments=None,),   
          ]
     )                                                                                                                                                                                                                                                                                                                 
 ] 

If this PR introduces a new feature, it is better to list some use cases here and update the documentation.

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@codecov
Copy link

codecov bot commented Oct 18, 2022

Codecov Report

Base: 0.02% // Head: 89.08% // Increases project coverage by +89.06% 🎉

Coverage data is based on head (54f73a0) compared to base (b8b31e9).
Patch has no changes to coverable lines.

Additional details and impacted files
@@             Coverage Diff              @@
##           dev-1.x    #1101       +/-   ##
============================================
+ Coverage     0.02%   89.08%   +89.06%     
============================================
  Files          121      143       +22     
  Lines         8217    10885     +2668     
  Branches      1368     1731      +363     
============================================
+ Hits             2     9697     +9695     
+ Misses        8215      947     -7268     
- Partials         0      241      +241     
Flag Coverage Δ
unittests 89.08% <ø> (+89.06%) ⬆️

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

Impacted Files Coverage Δ
mmcls/apis/inference.py 0.00% <0.00%> (ø)
mmcls/datasets/transforms/compose.py
mmcls/models/retrievers/__init__.py 100.00% <0.00%> (ø)
mmcls/models/retrievers/image2image.py 92.38% <0.00%> (ø)
mmcls/models/classifiers/hugging_face.py 25.33% <0.00%> (ø)
mmcls/models/utils/layer_scale.py 86.66% <0.00%> (ø)
mmcls/models/backbones/mvit.py 92.46% <0.00%> (ø)
mmcls/models/backbones/edgenext.py 95.20% <0.00%> (ø)
mmcls/models/classifiers/timm.py 25.67% <0.00%> (ø)
mmcls/models/backbones/deit3.py 94.52% <0.00%> (ø)
... and 133 more

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.

@Ezra-Yu Ezra-Yu changed the title [Feature] Add Switch Aug Hook [Feature] Add Switch Recipe Hook Nov 16, 2022
mmcls/engine/hooks/switch_recipe_hook.py Outdated Show resolved Hide resolved
@mzr1996 mzr1996 merged commit c3c1cb9 into open-mmlab:dev-1.x Nov 18, 2022
mzr1996 added a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
* add switch hook and UTs

* update doc

* update doc

* fix lint

* fix ci

* fix ci

* fix typo

* fix ci

* switchTrainAugHook to switchRecipeHook

* fix lint

* Refactor the `SwitchRecipeHook`.

* Fix windows CI

* Fix windows CI

* Fix windows CI.

Co-authored-by: mzr1996 <mzr1996@163.com>
@Ezra-Yu Ezra-Yu deleted the 1.x_progressive_learning branch April 13, 2023 11:57
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.

None yet

2 participants