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

[Enhancement] Support hrnet frozen stage #743

Merged
merged 2 commits into from
Aug 3, 2021
Merged

[Enhancement] Support hrnet frozen stage #743

merged 2 commits into from
Aug 3, 2021

Conversation

sshuair
Copy link
Contributor

@sshuair sshuair commented Jul 31, 2021

Motivation

Add new feature to support HRNet frozen stage like ResNet.

Modification

  • Add new parameter frozen_stages for HRNet.
  • Add new method _freeze_stages for HRNet.
  • Add new test function test_hrnet_backbone to test the frozen_stages.

BC-breaking (Optional)

No.

Use cases (Optional)

  1. use the frozen_stages from code
    model = HRNet(extra, frozen_stages=1) # frozen the first stage
  2. use the frozen_stages from config
    _base_ = './fcn_hr18_512x512_20k_voc12aug.py'
    model = dict(
        pretrained='open-mmlab://msra/hrnetv2_w18_small',
        backbone=dict(
            frozen_stages=1,
            extra=dict(
                stage1=dict(num_blocks=(2, )),
                stage2=dict(num_blocks=(2, 2)),
                stage3=dict(num_modules=3, num_blocks=(2, 2, 2)),
                stage4=dict(num_modules=2, num_blocks=(2, 2, 2, 2)))))

Checklist

  1. Pre-commit used.
  2. The modification is covered by complete unit tests.
  3. The modification has no potential influence on downstream projects.
  4. No need documents.

@codecov
Copy link

codecov bot commented Jul 31, 2021

Codecov Report

Merging #743 (7fae39c) into master (503ada7) will increase coverage by 0.02%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #743      +/-   ##
==========================================
+ Coverage   85.35%   85.37%   +0.02%     
==========================================
  Files         107      107              
  Lines        5823     5847      +24     
  Branches      952      960       +8     
==========================================
+ Hits         4970     4992      +22     
- Misses        672      673       +1     
- Partials      181      182       +1     
Flag Coverage Δ
unittests 85.36% <91.66%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
mmseg/models/backbones/hrnet.py 83.33% <91.66%> (+0.87%) ⬆️

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 503ada7...7fae39c. Read the comment docs.

@Junjun2016 Junjun2016 changed the title support hrnet frozen stage [Enhancement] Support hrnet frozen stage Aug 2, 2021
@Junjun2016
Copy link
Collaborator

Hi @sshuair
Thanks for your nice PR!

Copy link
Collaborator

@Junjun2016 Junjun2016 left a comment

Choose a reason for hiding this comment

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

It seems that the unittest of HRNet are missing in our original codebase.
We appreciate it a lot if you could add more unittests for HRNet.

@Junjun2016 Junjun2016 requested a review from xvjiarui August 2, 2021 08:10
@sshuair
Copy link
Contributor Author

sshuair commented Aug 2, 2021

It seems that the unittest of HRNet are missing in our original codebase.
We appreciate it a lot if you could add more unittests for HRNet.

@Junjun2016 I will add more HRNet unitest when I am free, but now I am busy at some work.
So, could you merge this PR to the master branch first.

@@ -575,6 +607,7 @@ def train(self, mode=True):
"""Convert the model into training mode will keeping the normalization
layer freezed."""
super(HRNet, self).train(mode)
self._freeze_stages()
Copy link
Collaborator

@xvjiarui xvjiarui Aug 2, 2021

Choose a reason for hiding this comment

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

Move this line inside train() like resnet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xvjiarui I did not find any difference between the resnet and hrnet about self._freeze_stages(). Could you give more information?

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry. My bad, I forgot to expand the collapsed code lines.

@xvjiarui xvjiarui merged commit f934084 into open-mmlab:master Aug 3, 2021
bowenroom pushed a commit to bowenroom/mmsegmentation that referenced this pull request Feb 25, 2022
* support hrnet frozen stage

* support hrnet frozen stage
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.

3 participants