-
-
Notifications
You must be signed in to change notification settings - Fork 5k
[WIP] Add ResNet-RS models #554
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8449932
Add ResNet-RS models
amaarora b117e16
Only include resnet-rs changes
amaarora 206407a
remove whitespace diff
amaarora 3f12ad3
remove whitespace diff
amaarora ca2877f
EOF newline
amaarora 3df71a1
Update time
amaarora 823162c
increase time
amaarora 530f8dd
Add first conv
amaarora 973b880
Try running only resnetv2_101x1_bitm on Linux runner
amaarora bf63f0c
Add to exclude filter
amaarora 094f04d
Run test_model_forward_features for all
amaarora f89bf2c
Add to exclude ftrs
amaarora a17ce02
back to defaults
amaarora 84fd045
only run test_forward_features
amaarora 6076728
run all tests
amaarora 59ca945
Run all tests
amaarora 3a73401
Add bigger resnetrs to model filters to fix Github CLI
amaarora ea9f935
Remove resnetv2_101x1_bitm from exclude feat features
amaarora e7df94a
Merge branch 'master' into resnet-rs
amaarora 69f8c71
Remove hardcoded values
amaarora c7b4041
Make sure reduction ratio in resnetrs is 0.25
amaarora 1f45c6e
There is no bias in replaced maxpool so remove it
amaarora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,7 +236,23 @@ def _cfg(url='', **kwargs): | |
interpolation='bicubic'), | ||
'resnetblur50': _cfg( | ||
url='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/resnetblur50-84f4748f.pth', | ||
interpolation='bicubic') | ||
interpolation='bicubic'), | ||
|
||
# ResNet-RS models | ||
'resnetrs50': _cfg( | ||
interpolation='bicubic', first_conv='conv1.0'), | ||
'resnetrs101': _cfg( | ||
interpolation='bicubic', first_conv='conv1.0'), | ||
'resnetrs152': _cfg( | ||
interpolation='bicubic', first_conv='conv1.0'), | ||
'resnetrs200': _cfg( | ||
interpolation='bicubic', first_conv='conv1.0'), | ||
'resnetrs270': _cfg( | ||
interpolation='bicubic', first_conv='conv1.0'), | ||
'resnetrs350': _cfg( | ||
interpolation='bicubic', first_conv='conv1.0'), | ||
'resnetrs420': _cfg( | ||
interpolation='bicubic', first_conv='conv1.0'), | ||
} | ||
|
||
|
||
|
@@ -318,7 +334,7 @@ class Bottleneck(nn.Module): | |
|
||
def __init__(self, inplanes, planes, stride=1, downsample=None, cardinality=1, base_width=64, | ||
reduce_first=1, dilation=1, first_dilation=None, act_layer=nn.ReLU, norm_layer=nn.BatchNorm2d, | ||
attn_layer=None, aa_layer=None, drop_block=None, drop_path=None): | ||
attn_layer=None, aa_layer=None, drop_block=None, drop_path=None, **kwargs): | ||
super(Bottleneck, self).__init__() | ||
|
||
width = int(math.floor(planes * (base_width / 64)) * cardinality) | ||
|
@@ -341,7 +357,7 @@ def __init__(self, inplanes, planes, stride=1, downsample=None, cardinality=1, b | |
self.conv3 = nn.Conv2d(width, outplanes, kernel_size=1, bias=False) | ||
self.bn3 = norm_layer(outplanes) | ||
|
||
self.se = create_attn(attn_layer, outplanes) | ||
self.se = create_attn(attn_layer, outplanes, **kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These |
||
|
||
self.act3 = act_layer(inplace=True) | ||
self.downsample = downsample | ||
|
@@ -545,11 +561,12 @@ def __init__(self, block, layers, num_classes=1000, in_chans=3, | |
cardinality=1, base_width=64, stem_width=64, stem_type='', | ||
output_stride=32, block_reduce_first=1, down_kernel_size=1, avg_down=False, | ||
act_layer=nn.ReLU, norm_layer=nn.BatchNorm2d, aa_layer=None, drop_rate=0.0, drop_path_rate=0., | ||
drop_block_rate=0., global_pool='avg', zero_init_last_bn=True, block_args=None): | ||
drop_block_rate=0., global_pool='avg', zero_init_last_bn=True, block_args=None, replace_stem_max_pool=False): | ||
block_args = block_args or dict() | ||
assert output_stride in (8, 16, 32) | ||
self.num_classes = num_classes | ||
self.drop_rate = drop_rate | ||
self.replace_stem_max_pool = replace_stem_max_pool | ||
super(ResNet, self).__init__() | ||
|
||
# Stem | ||
|
@@ -574,12 +591,19 @@ def __init__(self, block, layers, num_classes=1000, in_chans=3, | |
self.feature_info = [dict(num_chs=inplanes, reduction=2, module='act1')] | ||
|
||
# Stem Pooling | ||
if aa_layer is not None: | ||
self.maxpool = nn.Sequential(*[ | ||
nn.MaxPool2d(kernel_size=3, stride=1, padding=1), | ||
aa_layer(channels=inplanes, stride=2)]) | ||
if not self.replace_stem_max_pool: | ||
if aa_layer is not None: | ||
self.maxpool = nn.Sequential(*[ | ||
nn.MaxPool2d(kernel_size=3, stride=1, padding=1), | ||
aa_layer(channels=inplanes, stride=2)]) | ||
else: | ||
self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) | ||
else: | ||
self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) | ||
self.maxpool = nn.Sequential(*[ | ||
nn.Conv2d(inplanes, inplanes, 3, stride=2, padding=1, bias=False), | ||
norm_layer(inplanes), | ||
act_layer(inplace=True) | ||
]) | ||
|
||
# Feature Blocks | ||
channels = [64, 128, 256, 512] | ||
|
@@ -1065,6 +1089,63 @@ def ecaresnet50d(pretrained=False, **kwargs): | |
return _create_resnet('ecaresnet50d', pretrained, **model_args) | ||
|
||
|
||
@register_model | ||
def resnetrs50(pretrained=False, **kwargs): | ||
model_args = dict( | ||
block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep', replace_stem_max_pool=True, | ||
avg_down=True, block_args=dict(attn_layer='se', reduction_ratio=0.25), **kwargs) | ||
return _create_resnet('resnetrs50', pretrained, **model_args) | ||
|
||
|
||
@register_model | ||
def resnetrs101(pretrained=False, **kwargs): | ||
model_args = dict( | ||
block=Bottleneck, layers=[3, 4, 23, 3], stem_width=32, stem_type='deep', replace_stem_max_pool=True, | ||
avg_down=True, block_args=dict(attn_layer='se', reduction_ratio=0.25), **kwargs) | ||
return _create_resnet('resnetrs101', pretrained, **model_args) | ||
|
||
|
||
@register_model | ||
def resnetrs152(pretrained=False, **kwargs): | ||
model_args = dict( | ||
block=Bottleneck, layers=[3, 8, 36, 3], stem_width=32, stem_type='deep', replace_stem_max_pool=True, | ||
avg_down=True, block_args=dict(attn_layer='se', reduction_ratio=0.25), **kwargs) | ||
return _create_resnet('resnetrs152', pretrained, **model_args) | ||
|
||
|
||
@register_model | ||
def resnetrs200(pretrained=False, **kwargs): | ||
model_args = dict( | ||
block=Bottleneck, layers=[3, 24, 36, 3], stem_width=32, stem_type='deep', replace_stem_max_pool=True, | ||
avg_down=True, block_args=dict(attn_layer='se', reduction_ratio=0.25), **kwargs) | ||
return _create_resnet('resnetrs200', pretrained, **model_args) | ||
|
||
|
||
@register_model | ||
def resnetrs270(pretrained=False, **kwargs): | ||
model_args = dict( | ||
block=Bottleneck, layers=[4, 29, 53, 4], stem_width=32, stem_type='deep', replace_stem_max_pool=True, | ||
avg_down=True, block_args=dict(attn_layer='se', reduction_ratio=0.25), **kwargs) | ||
return _create_resnet('resnetrs270', pretrained, **model_args) | ||
|
||
|
||
|
||
@register_model | ||
def resnetrs350(pretrained=False, **kwargs): | ||
model_args = dict( | ||
block=Bottleneck, layers=[4, 36, 72, 4], stem_width=32, stem_type='deep', replace_stem_max_pool=True, | ||
avg_down=True, block_args=dict(attn_layer='se', reduction_ratio=0.25), **kwargs) | ||
return _create_resnet('resnetrs350', pretrained, **model_args) | ||
|
||
|
||
@register_model | ||
def resnetrs420(pretrained=False, **kwargs): | ||
model_args = dict( | ||
block=Bottleneck, layers=[4, 44, 87, 4], stem_width=32, stem_type='deep', replace_stem_max_pool=True, | ||
avg_down=True, block_args=dict(attn_layer='se', reduction_ratio=0.25), **kwargs) | ||
return _create_resnet('resnetrs420', pretrained, **model_args) | ||
|
||
|
||
@register_model | ||
def ecaresnet50d_pruned(pretrained=False, **kwargs): | ||
"""Constructs a ResNet-50-D model pruned with eca. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@rwightman FYI this is change that you might want to review specifically. I have added
**kwargs
toBottleneck
block that get passed to attention layers.This is to pass in
reduction_ratio=0.25
forse
layers as mentioned in the paper.