-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 RepVGG backbone and checkpoints #414
Conversation
Codecov Report
@@ Coverage Diff @@
## master #414 +/- ##
==========================================
+ Coverage 77.29% 77.97% +0.67%
==========================================
Files 100 101 +1
Lines 5356 5547 +191
Branches 883 915 +32
==========================================
+ Hits 4140 4325 +185
- Misses 1098 1101 +3
- Partials 118 121 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- name convert_repvggblock_param_to_deploy.py publish_repvgg.py is too long for a tool script.
- unit tests for reparam is needed, because is it the keypoint code in this backbone.
parser.add_argument( | ||
'save_path', | ||
help='The path where the converted checkpoint file is stored.') | ||
parser.add_argument( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"device" here is redundant. we did not need to use GPU.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved. Unit tests have been included for repvgg reparameterization.
mmcls/models/backbones/repvgg.py
Outdated
input_dim = self.in_channels // self.groups | ||
conv_weight = torch.zeros((self.in_channels, input_dim, 3, 3), | ||
dtype=branch.weight.dtype) | ||
for i in range(self.in_channels): | ||
conv_weight[i, i % input_dim, 1, 1] = 1 | ||
conv_weight = conv_weight.to(branch.weight.device) | ||
running_mean = branch.running_mean | ||
running_var = branch.running_var | ||
gamma = branch.weight | ||
beta = branch.bias | ||
eps = branch.eps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is better to extract a function called identity_to_conv3×3,then the function "fuse" and "reparameterize" will be more clear.
some important lines need comments, such line 222-226.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
mmcls/models/backbones/repvgg.py
Outdated
""" | ||
weight_3x3, bias_3x3 = self._fuse_conv_bn(self.branch_3x3) | ||
weight_1x1, bias_1x1 = self._fuse_conv_bn(self.branch_1x1) | ||
weight_1x1 = F.pad(weight_1x1, [1, 1, 1, 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here adding "value=0" in F.pad() will help other programers to understand this line.
a comment is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
mmcls/models/backbones/repvgg.py
Outdated
if len(outs) == 1: | ||
return outs[0] | ||
else: | ||
return tuple(outs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return tuple(outs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I use it like this now?
mmcls/models/backbones/repvgg.py
Outdated
channels = out_channels | ||
|
||
def _make_stage(self, in_channels, out_channels, num_blocks, stride, | ||
dilation, next_create_block_idx, se_cfg, init_cfg): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"next_create_block_idx" is confused, Is it possible not to use this parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
mmcls/models/backbones/repvgg.py
Outdated
dtype=branch.weight.dtype) | ||
for i in range(self.in_channels): | ||
conv_weight[i, i % input_dim, 1, 1] = 1 | ||
conv_weight = conv_weight.to(branch.weight.device) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this line Redundant since line 224?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
…g.py, and delete setting about device.
mmcls/models/backbones/repvgg.py
Outdated
""" | ||
|
||
optional_groupwise_layers = [ | ||
2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these non-zero even-numbered layers?
configs/repvgg/deploy/repvggA0_4xb64-coslr-120e_in-1k_deploy.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Ma Zerun <mzr1996@163.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Add RepVGG code. * Add se_module as plugin. * Add the repvggA0 primitive config * Change repvggA0.py to fit mmcls * Add RepVGG configs * Add repvgg_to_mmcls * Add tools/deployment/convert_repvggblock_param_to_deploy.py * Change configs/repvgg/README.md * Streamlining the number of configuration files. * Fix lints * Delete plugins * Delete code about plugin. * Modify the code for using se module. * Modify config to fit repvgg with se. * Change se_cfg to allow loading of pre-training parameters. * Reduce the complexity of the configuration file. * Finsh unitest for repvgg. * Fix bug about se in repvgg_to_mmcls. * Rename convert_repvggblock_param_to_deploy.py to reparameterize_repvgg.py, and delete setting about device. * test commit * test commit * test commit command * Modify repvgg.py to make the code more readable. * Add value=0 in F.pad() * Add se_cfg to arch_settings. * Fix bug. * modeify some attr name and Update unit tests * rename stage_0 to stem and branch_identity to branch_norm * update unit tests * add m.eval in unit tests * [Enhance] Enhence SE layer to support custom squeeze channels. (open-mmlab#417) * add enhenced SE * Update * rm basechannel * fix docstring * Update se_layer.py fix docstring * [Docs] Add algorithm readme and update meta yml (open-mmlab#418) * Add README.md for models without checkpoints. * Update model-index.yml * Update metafile.yml of seresnet * [Enhance] Add `hparams` argument in `AutoAugment` and `RandAugment` and some other improvement. (open-mmlab#398) * Add hparams argument in `AutoAugment` and `RandAugment`. And `pad_val` supports sequence instead of tuple only. * Add unit tests for `AutoAugment` and `hparams` in `RandAugment`. * Use smaller test image to speed up uni tests. * Use hparams to simplify RandAugment config in swin-transformer. * Rename augment config name from `pipeline` to `pipelines`. * Add some commnet ad docstring. * [Feature] Support classwise weight in losses (open-mmlab#388) * Add classwise weight in losses:CE,BCE,softBCE * Update unit test * rm some extra code * rm some extra code * fix broadcast * fix broadcast * update unit tests * use new_tensor * fix lint * [Enhance] Better result visualization (open-mmlab#419) * Imporve result visualization to support wait time and change the backend to matplotlib. * Add unit test for visualization * Add adaptive dpi function * Rename `imshow_cls_result` to `imshow_infos`. * Support str in `imshow_infos` * Improve docstring. * Bump version to v0.15.0 (open-mmlab#426) * [CI] Add PyTorch 1.9 and Python 3.9 build workflow, and remove some CI. (open-mmlab#422) * Add PyTorch 1.9 build workflow, and remove some CI. * Add Python 3.9 CI * Show Python 3.9 support. * [Enhance] Rename the option `--options` in some tools to `--cfg-options`. (open-mmlab#425) * [Docs] Fix sphinx version (open-mmlab#429) * [Docs] Add `CITATION.cff` (open-mmlab#428) * Add CITATION.cff * Fix typo in setup.py * Change author in setup.py * modeify some attr name and Update unit tests * rename stage_0 to stem and branch_identity to branch_norm * update unit tests * add m.eval in unit tests * Update unit tests * refactor * refactor * Alignment inference accuracy * Update configs, readme and metafile * Update readme * return tuple and fix metafile * fix unit test * rm regnet and classifiers changes * update auto_aug * update metafile & readme * use delattr * rename cfgs * Update checkpoint url * Update readme * Rename config files. * Update readme and metafile * add comment * Update mmcls/models/backbones/repvgg.py Co-authored-by: Ma Zerun <mzr1996@163.com> * Update docstring * Improve docstring. * Update unittest_testblock Co-authored-by: Ezra-Yu <1105212286@qq.com> Co-authored-by: Ma Zerun <mzr1996@163.com>
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
Add RepVGG backbone.
Modification
Add the RepVGG source code, and its accompanying configuration files and related files for deployment..
BC-breaking (Optional)
No
Use cases (Optional)
No
Checklist
Before PR:
After PR: