-
Notifications
You must be signed in to change notification settings - Fork 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] Support RepLKnet backbone. #1129
Conversation
tools/test.py
Outdated
@@ -138,6 +138,7 @@ def main(): | |||
# load config | |||
cfg = Config.fromfile(args.config) | |||
cfg = merge_args(cfg, args) | |||
print(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.
Please remove the unrelated modification.
mmcls/models/backbones/replknet.py
Outdated
# def create_RepLKNet31B(drop_path_rate=0.3, num_classes=1000, with_cp=True, small_kernel_merged=False): | ||
# return RepLKNet(arch='31B') | ||
|
||
# def create_RepLKNet31L(drop_path_rate=0.3, num_classes=1000, with_cp=True, small_kernel_merged=False): | ||
# return RepLKNet(large_kernel_sizes=[31,29,27,13], layers=[2,2,18,2], channels=[192,384,768,1536], | ||
# drop_path_rate=drop_path_rate, small_kernel=5, num_classes=num_classes, with_cp=with_cp, | ||
# small_kernel_merged=small_kernel_merged) | ||
|
||
# def create_RepLKNetXL(drop_path_rate=0.3, num_classes=1000, with_cp=True, small_kernel_merged=False): | ||
# return RepLKNet(large_kernel_sizes=[27,27,27,13], layers=[2,2,18,2], channels=[256,512,1024,2048], | ||
# drop_path_rate=drop_path_rate, small_kernel=None, dw_ratio=1.5, | ||
# num_classes=num_classes, with_cp=with_cp, | ||
# small_kernel_merged=small_kernel_merged) | ||
|
||
# if __name__ == '__main__': | ||
# model = create_RepLKNet31B(small_kernel_merged=False) | ||
# model.eval() | ||
# print('------------------- training-time model -------------') | ||
# for i in model.state_dict().keys(): | ||
# print(i) | ||
# print(model) | ||
# x = torch.randn(2, 3, 224, 224) | ||
# origin_y = model(x) | ||
# model.switch_to_deploy() | ||
# print('------------------- after re-param -------------') | ||
# print(model) | ||
# reparam_y = model(x) | ||
# print('------------------- the difference is ------------------------') | ||
# print((origin_y - reparam_y).abs().sum()) |
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.
Remove useless comments.
mmcls/models/backbones/replknet.py
Outdated
def get_conv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias): | ||
if type(kernel_size) is int: | ||
use_large_impl = kernel_size > 5 | ||
else: | ||
assert len(kernel_size) == 2 and kernel_size[0] == kernel_size[1] | ||
use_large_impl = kernel_size[0] > 5 | ||
has_large_impl = 'LARGE_KERNEL_CONV_IMPL' in os.environ | ||
if has_large_impl and in_channels == out_channels and out_channels == groups and use_large_impl and stride == 1 and padding == kernel_size // 2 and dilation == 1: | ||
sys.path.append(os.environ['LARGE_KERNEL_CONV_IMPL']) | ||
# Please follow the instructions https://github.com/DingXiaoH/RepLKNet-pytorch/blob/main/README.md | ||
# export LARGE_KERNEL_CONV_IMPL=absolute_path_to_where_you_cloned_the_example (i.e., depthwise_conv2d_implicit_gemm.py) | ||
# TODO more efficient PyTorch implementations of large-kernel convolutions. Pull requests are welcomed. | ||
# Or you may try MegEngine. We have integrated an efficient implementation into MegEngine and it will automatically use it. | ||
from depthwise_conv2d_implicit_gemm import DepthWiseConv2dImplicitGEMM | ||
return DepthWiseConv2dImplicitGEMM(in_channels, kernel_size, bias=bias) | ||
else: | ||
return nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride, | ||
padding=padding, dilation=dilation, groups=groups, bias=bias) |
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.
Since we don't have the DepthWiseConv2dImplicitGEMM
in MMCV, please remove this function.
You can also add this operator to mmcv package.
mmcls/models/backbones/replknet.py
Outdated
use_sync_bn = False | ||
|
||
def enable_sync_bn(): | ||
global use_sync_bn | ||
use_sync_bn = True | ||
|
||
def get_bn(channels): | ||
if use_sync_bn: | ||
return nn.SyncBatchNorm(channels) | ||
else: | ||
return nn.BatchNorm2d(channels) |
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.
We have our sync_bn
configuration, please use norm_cfg
instead of this kind of code.
self.small_kernel_merged = True | ||
|
||
|
||
class ConvFFN(BaseModule): |
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.
where is FFN
?
|
||
@MODELS.register_module() | ||
class RepLKNet(BaseBackbone): | ||
|
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.
Missing docstring
Codecov ReportBase: 0.02% // Head: 89.16% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## dev-1.x #1129 +/- ##
============================================
+ Coverage 0.02% 89.16% +89.14%
============================================
Files 121 144 +23
Lines 8217 11086 +2869
Branches 1368 1764 +396
============================================
+ Hits 2 9885 +9883
+ Misses 8215 952 -7263
- Partials 0 249 +249
Flags with carried forward coverage won't be shown. Click here to find out 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. |
* update replknet configs * update replknet test * update replknet model * update replknet model * update replknet model * update replknet model * Fix docs and config names Co-authored-by: mzr1996 <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 RepLKNet inference and test files.
Modification
Add RepLKNet inference and test files.
Checklist
After PR: