From c0d7388a1b2880f37aa22a594cb47be0351024d6 Mon Sep 17 00:00:00 2001 From: Ross Wightman Date: Sat, 7 Jan 2023 16:29:12 -0800 Subject: [PATCH] Improving kwarg merging in more models --- timm/models/dpn.py | 71 +++++--- timm/models/maxxvit.py | 25 ++- timm/models/res2net.py | 28 ++-- timm/models/resnest.py | 32 ++-- timm/models/resnet.py | 372 ++++++++++++++++++++--------------------- 5 files changed, 292 insertions(+), 236 deletions(-) diff --git a/timm/models/dpn.py b/timm/models/dpn.py index 87bd918f..6dbabad2 100644 --- a/timm/models/dpn.py +++ b/timm/models/dpn.py @@ -15,7 +15,7 @@ import torch.nn as nn import torch.nn.functional as F from timm.data import IMAGENET_DPN_MEAN, IMAGENET_DPN_STD, IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD -from timm.layers import BatchNormAct2d, ConvNormAct, create_conv2d, create_classifier +from timm.layers import BatchNormAct2d, ConvNormAct, create_conv2d, create_classifier, get_norm_act_layer from ._builder import build_model_with_cfg from ._registry import register_model @@ -33,6 +33,7 @@ def _cfg(url='', **kwargs): default_cfgs = { + 'dpn48b': _cfg(mean=IMAGENET_DEFAULT_MEAN, std=IMAGENET_DEFAULT_STD), 'dpn68': _cfg( url='https://github.com/rwightman/pytorch-dpn-pretrained/releases/download/v0.1/dpn68-66bebafa7.pth'), 'dpn68b': _cfg( @@ -82,7 +83,16 @@ class BnActConv2d(nn.Module): class DualPathBlock(nn.Module): def __init__( - self, in_chs, num_1x1_a, num_3x3_b, num_1x1_c, inc, groups, block_type='normal', b=False): + self, + in_chs, + num_1x1_a, + num_3x3_b, + num_1x1_c, + inc, + groups, + block_type='normal', + b=False, + ): super(DualPathBlock, self).__init__() self.num_1x1_c = num_1x1_c self.inc = inc @@ -167,16 +177,31 @@ class DualPathBlock(nn.Module): class DPN(nn.Module): def __init__( - self, small=False, num_init_features=64, k_r=96, groups=32, global_pool='avg', - b=False, k_sec=(3, 4, 20, 3), inc_sec=(16, 32, 24, 128), output_stride=32, - num_classes=1000, in_chans=3, drop_rate=0., fc_act_layer=nn.ELU): + self, + num_classes=1000, + in_chans=3, + output_stride=32, + global_pool='avg', + k_sec=(3, 4, 20, 3), + inc_sec=(16, 32, 24, 128), + k_r=96, + groups=32, + small=False, + num_init_features=64, + b=False, + drop_rate=0., + norm_layer='batchnorm2d', + act_layer='relu', + fc_act_layer=nn.ELU, + ): super(DPN, self).__init__() self.num_classes = num_classes self.drop_rate = drop_rate self.b = b assert output_stride == 32 # FIXME look into dilation support - norm_layer = partial(BatchNormAct2d, eps=.001) - fc_norm_layer = partial(BatchNormAct2d, eps=.001, act_layer=fc_act_layer, inplace=False) + + norm_layer = partial(get_norm_act_layer(norm_layer, act_layer=act_layer), eps=.001) + fc_norm_layer = partial(get_norm_act_layer(norm_layer, act_layer=fc_act_layer), eps=.001, inplace=False) bw_factor = 1 if small else 4 blocks = OrderedDict() @@ -291,49 +316,57 @@ def _create_dpn(variant, pretrained=False, **kwargs): **kwargs) +@register_model +def dpn48b(pretrained=False, **kwargs): + model_kwargs = dict( + small=True, num_init_features=10, k_r=128, groups=32, + b=True, k_sec=(3, 4, 6, 3), inc_sec=(16, 32, 32, 64), act_layer='silu') + return _create_dpn('dpn48b', pretrained=pretrained, **dict(model_kwargs, **kwargs)) + + @register_model def dpn68(pretrained=False, **kwargs): model_kwargs = dict( small=True, num_init_features=10, k_r=128, groups=32, - k_sec=(3, 4, 12, 3), inc_sec=(16, 32, 32, 64), **kwargs) - return _create_dpn('dpn68', pretrained=pretrained, **model_kwargs) + k_sec=(3, 4, 12, 3), inc_sec=(16, 32, 32, 64)) + return _create_dpn('dpn68', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model def dpn68b(pretrained=False, **kwargs): model_kwargs = dict( small=True, num_init_features=10, k_r=128, groups=32, - b=True, k_sec=(3, 4, 12, 3), inc_sec=(16, 32, 32, 64), **kwargs) - return _create_dpn('dpn68b', pretrained=pretrained, **model_kwargs) + b=True, k_sec=(3, 4, 12, 3), inc_sec=(16, 32, 32, 64)) + return _create_dpn('dpn68b', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model def dpn92(pretrained=False, **kwargs): model_kwargs = dict( num_init_features=64, k_r=96, groups=32, - k_sec=(3, 4, 20, 3), inc_sec=(16, 32, 24, 128), **kwargs) - return _create_dpn('dpn92', pretrained=pretrained, **model_kwargs) + k_sec=(3, 4, 20, 3), inc_sec=(16, 32, 24, 128)) + return _create_dpn('dpn92', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model def dpn98(pretrained=False, **kwargs): model_kwargs = dict( num_init_features=96, k_r=160, groups=40, - k_sec=(3, 6, 20, 3), inc_sec=(16, 32, 32, 128), **kwargs) - return _create_dpn('dpn98', pretrained=pretrained, **model_kwargs) + k_sec=(3, 6, 20, 3), inc_sec=(16, 32, 32, 128)) + return _create_dpn('dpn98', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model def dpn131(pretrained=False, **kwargs): model_kwargs = dict( num_init_features=128, k_r=160, groups=40, - k_sec=(4, 8, 28, 3), inc_sec=(16, 32, 32, 128), **kwargs) - return _create_dpn('dpn131', pretrained=pretrained, **model_kwargs) + k_sec=(4, 8, 28, 3), inc_sec=(16, 32, 32, 128)) + return _create_dpn('dpn131', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model def dpn107(pretrained=False, **kwargs): model_kwargs = dict( num_init_features=128, k_r=200, groups=50, - k_sec=(4, 8, 20, 3), inc_sec=(20, 64, 64, 128), **kwargs) - return _create_dpn('dpn107', pretrained=pretrained, **model_kwargs) + k_sec=(4, 8, 20, 3), inc_sec=(20, 64, 64, 128)) + return _create_dpn('dpn107', pretrained=pretrained, **dict(model_kwargs, **kwargs)) diff --git a/timm/models/maxxvit.py b/timm/models/maxxvit.py index 1170e7e3..d68301b1 100644 --- a/timm/models/maxxvit.py +++ b/timm/models/maxxvit.py @@ -1116,6 +1116,26 @@ class NormMlpHead(nn.Module): return x +def _overlay_kwargs(cfg: MaxxVitCfg, **kwargs): + transformer_kwargs = {} + conv_kwargs = {} + base_kwargs = {} + for k, v in kwargs.items(): + if k.startswith('transformer_'): + transformer_kwargs[k.replace('transformer_', '')] = v + elif k.startswith('conv_'): + conv_kwargs[k.replace('conv_', '')] = v + else: + base_kwargs[k] = v + cfg = replace( + cfg, + transformer_cfg=replace(cfg.transformer_cfg, **transformer_kwargs), + conv_cfg=replace(cfg.conv_cfg, **conv_kwargs), + **base_kwargs + ) + return cfg + + class MaxxVit(nn.Module): """ CoaTNet + MaxVit base model. @@ -1130,10 +1150,13 @@ class MaxxVit(nn.Module): num_classes: int = 1000, global_pool: str = 'avg', drop_rate: float = 0., - drop_path_rate: float = 0. + drop_path_rate: float = 0., + **kwargs, ): super().__init__() img_size = to_2tuple(img_size) + if kwargs: + cfg = _overlay_kwargs(cfg, **kwargs) transformer_cfg = cfg_window_size(cfg.transformer_cfg, img_size) self.num_classes = num_classes self.global_pool = global_pool diff --git a/timm/models/res2net.py b/timm/models/res2net.py index 607ba722..29a49953 100644 --- a/timm/models/res2net.py +++ b/timm/models/res2net.py @@ -156,8 +156,8 @@ def res2net50_26w_4s(pretrained=False, **kwargs): pretrained (bool): If True, returns a model pre-trained on ImageNet """ model_args = dict( - block=Bottle2neck, layers=[3, 4, 6, 3], base_width=26, block_args=dict(scale=4), **kwargs) - return _create_res2net('res2net50_26w_4s', pretrained, **model_args) + block=Bottle2neck, layers=[3, 4, 6, 3], base_width=26, block_args=dict(scale=4)) + return _create_res2net('res2net50_26w_4s', pretrained, **dict(model_args, **kwargs)) @register_model @@ -167,8 +167,8 @@ def res2net101_26w_4s(pretrained=False, **kwargs): pretrained (bool): If True, returns a model pre-trained on ImageNet """ model_args = dict( - block=Bottle2neck, layers=[3, 4, 23, 3], base_width=26, block_args=dict(scale=4), **kwargs) - return _create_res2net('res2net101_26w_4s', pretrained, **model_args) + block=Bottle2neck, layers=[3, 4, 23, 3], base_width=26, block_args=dict(scale=4)) + return _create_res2net('res2net101_26w_4s', pretrained, **dict(model_args, **kwargs)) @register_model @@ -178,8 +178,8 @@ def res2net50_26w_6s(pretrained=False, **kwargs): pretrained (bool): If True, returns a model pre-trained on ImageNet """ model_args = dict( - block=Bottle2neck, layers=[3, 4, 6, 3], base_width=26, block_args=dict(scale=6), **kwargs) - return _create_res2net('res2net50_26w_6s', pretrained, **model_args) + block=Bottle2neck, layers=[3, 4, 6, 3], base_width=26, block_args=dict(scale=6)) + return _create_res2net('res2net50_26w_6s', pretrained, **dict(model_args, **kwargs)) @register_model @@ -189,8 +189,8 @@ def res2net50_26w_8s(pretrained=False, **kwargs): pretrained (bool): If True, returns a model pre-trained on ImageNet """ model_args = dict( - block=Bottle2neck, layers=[3, 4, 6, 3], base_width=26, block_args=dict(scale=8), **kwargs) - return _create_res2net('res2net50_26w_8s', pretrained, **model_args) + block=Bottle2neck, layers=[3, 4, 6, 3], base_width=26, block_args=dict(scale=8)) + return _create_res2net('res2net50_26w_8s', pretrained, **dict(model_args, **kwargs)) @register_model @@ -200,8 +200,8 @@ def res2net50_48w_2s(pretrained=False, **kwargs): pretrained (bool): If True, returns a model pre-trained on ImageNet """ model_args = dict( - block=Bottle2neck, layers=[3, 4, 6, 3], base_width=48, block_args=dict(scale=2), **kwargs) - return _create_res2net('res2net50_48w_2s', pretrained, **model_args) + block=Bottle2neck, layers=[3, 4, 6, 3], base_width=48, block_args=dict(scale=2)) + return _create_res2net('res2net50_48w_2s', pretrained, **dict(model_args, **kwargs)) @register_model @@ -211,8 +211,8 @@ def res2net50_14w_8s(pretrained=False, **kwargs): pretrained (bool): If True, returns a model pre-trained on ImageNet """ model_args = dict( - block=Bottle2neck, layers=[3, 4, 6, 3], base_width=14, block_args=dict(scale=8), **kwargs) - return _create_res2net('res2net50_14w_8s', pretrained, **model_args) + block=Bottle2neck, layers=[3, 4, 6, 3], base_width=14, block_args=dict(scale=8)) + return _create_res2net('res2net50_14w_8s', pretrained, **dict(model_args, **kwargs)) @register_model @@ -222,5 +222,5 @@ def res2next50(pretrained=False, **kwargs): pretrained (bool): If True, returns a model pre-trained on ImageNet """ model_args = dict( - block=Bottle2neck, layers=[3, 4, 6, 3], base_width=4, cardinality=8, block_args=dict(scale=4), **kwargs) - return _create_res2net('res2next50', pretrained, **model_args) + block=Bottle2neck, layers=[3, 4, 6, 3], base_width=4, cardinality=8, block_args=dict(scale=4)) + return _create_res2net('res2next50', pretrained, **dict(model_args, **kwargs)) diff --git a/timm/models/resnest.py b/timm/models/resnest.py index 853ee1d0..38303f9c 100644 --- a/timm/models/resnest.py +++ b/timm/models/resnest.py @@ -163,8 +163,8 @@ def resnest14d(pretrained=False, **kwargs): model_kwargs = dict( block=ResNestBottleneck, layers=[1, 1, 1, 1], stem_type='deep', stem_width=32, avg_down=True, base_width=64, cardinality=1, - block_args=dict(radix=2, avd=True, avd_first=False), **kwargs) - return _create_resnest('resnest14d', pretrained=pretrained, **model_kwargs) + block_args=dict(radix=2, avd=True, avd_first=False)) + return _create_resnest('resnest14d', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model @@ -174,8 +174,8 @@ def resnest26d(pretrained=False, **kwargs): model_kwargs = dict( block=ResNestBottleneck, layers=[2, 2, 2, 2], stem_type='deep', stem_width=32, avg_down=True, base_width=64, cardinality=1, - block_args=dict(radix=2, avd=True, avd_first=False), **kwargs) - return _create_resnest('resnest26d', pretrained=pretrained, **model_kwargs) + block_args=dict(radix=2, avd=True, avd_first=False)) + return _create_resnest('resnest26d', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model @@ -186,8 +186,8 @@ def resnest50d(pretrained=False, **kwargs): model_kwargs = dict( block=ResNestBottleneck, layers=[3, 4, 6, 3], stem_type='deep', stem_width=32, avg_down=True, base_width=64, cardinality=1, - block_args=dict(radix=2, avd=True, avd_first=False), **kwargs) - return _create_resnest('resnest50d', pretrained=pretrained, **model_kwargs) + block_args=dict(radix=2, avd=True, avd_first=False)) + return _create_resnest('resnest50d', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model @@ -198,8 +198,8 @@ def resnest101e(pretrained=False, **kwargs): model_kwargs = dict( block=ResNestBottleneck, layers=[3, 4, 23, 3], stem_type='deep', stem_width=64, avg_down=True, base_width=64, cardinality=1, - block_args=dict(radix=2, avd=True, avd_first=False), **kwargs) - return _create_resnest('resnest101e', pretrained=pretrained, **model_kwargs) + block_args=dict(radix=2, avd=True, avd_first=False)) + return _create_resnest('resnest101e', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model @@ -210,8 +210,8 @@ def resnest200e(pretrained=False, **kwargs): model_kwargs = dict( block=ResNestBottleneck, layers=[3, 24, 36, 3], stem_type='deep', stem_width=64, avg_down=True, base_width=64, cardinality=1, - block_args=dict(radix=2, avd=True, avd_first=False), **kwargs) - return _create_resnest('resnest200e', pretrained=pretrained, **model_kwargs) + block_args=dict(radix=2, avd=True, avd_first=False)) + return _create_resnest('resnest200e', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model @@ -222,8 +222,8 @@ def resnest269e(pretrained=False, **kwargs): model_kwargs = dict( block=ResNestBottleneck, layers=[3, 30, 48, 8], stem_type='deep', stem_width=64, avg_down=True, base_width=64, cardinality=1, - block_args=dict(radix=2, avd=True, avd_first=False), **kwargs) - return _create_resnest('resnest269e', pretrained=pretrained, **model_kwargs) + block_args=dict(radix=2, avd=True, avd_first=False)) + return _create_resnest('resnest269e', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model @@ -233,8 +233,8 @@ def resnest50d_4s2x40d(pretrained=False, **kwargs): model_kwargs = dict( block=ResNestBottleneck, layers=[3, 4, 6, 3], stem_type='deep', stem_width=32, avg_down=True, base_width=40, cardinality=2, - block_args=dict(radix=4, avd=True, avd_first=True), **kwargs) - return _create_resnest('resnest50d_4s2x40d', pretrained=pretrained, **model_kwargs) + block_args=dict(radix=4, avd=True, avd_first=True)) + return _create_resnest('resnest50d_4s2x40d', pretrained=pretrained, **dict(model_kwargs, **kwargs)) @register_model @@ -244,5 +244,5 @@ def resnest50d_1s4x24d(pretrained=False, **kwargs): model_kwargs = dict( block=ResNestBottleneck, layers=[3, 4, 6, 3], stem_type='deep', stem_width=32, avg_down=True, base_width=24, cardinality=4, - block_args=dict(radix=1, avd=True, avd_first=True), **kwargs) - return _create_resnest('resnest50d_1s4x24d', pretrained=pretrained, **model_kwargs) + block_args=dict(radix=1, avd=True, avd_first=True)) + return _create_resnest('resnest50d_1s4x24d', pretrained=pretrained, **dict(model_kwargs, **kwargs)) diff --git a/timm/models/resnet.py b/timm/models/resnet.py index a783e3e1..b3c041c4 100644 --- a/timm/models/resnet.py +++ b/timm/models/resnet.py @@ -704,7 +704,7 @@ class ResNet(nn.Module): self.num_classes = num_classes self.drop_rate = drop_rate self.grad_checkpointing = False - + act_layer = get_act_layer(act_layer) norm_layer = get_norm_layer(norm_layer) @@ -845,77 +845,72 @@ def _create_resnet(variant, pretrained=False, **kwargs): def resnet10t(pretrained=False, **kwargs): """Constructs a ResNet-10-T model. """ - model_args = dict( - block=BasicBlock, layers=[1, 1, 1, 1], stem_width=32, stem_type='deep_tiered', avg_down=True, **kwargs) - return _create_resnet('resnet10t', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[1, 1, 1, 1], stem_width=32, stem_type='deep_tiered', avg_down=True) + return _create_resnet('resnet10t', pretrained, **dict(model_args, **kwargs)) @register_model def resnet14t(pretrained=False, **kwargs): """Constructs a ResNet-14-T model. """ - model_args = dict( - block=Bottleneck, layers=[1, 1, 1, 1], stem_width=32, stem_type='deep_tiered', avg_down=True, **kwargs) - return _create_resnet('resnet14t', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[1, 1, 1, 1], stem_width=32, stem_type='deep_tiered', avg_down=True) + return _create_resnet('resnet14t', pretrained, **dict(model_args, **kwargs)) @register_model def resnet18(pretrained=False, **kwargs): """Constructs a ResNet-18 model. """ - model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2], **kwargs) - return _create_resnet('resnet18', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2]) + return _create_resnet('resnet18', pretrained, **dict(model_args, **kwargs)) @register_model def resnet18d(pretrained=False, **kwargs): """Constructs a ResNet-18-D model. """ - model_args = dict( - block=BasicBlock, layers=[2, 2, 2, 2], stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnet18d', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2], stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnet18d', pretrained, **dict(model_args, **kwargs)) @register_model def resnet34(pretrained=False, **kwargs): """Constructs a ResNet-34 model. """ - model_args = dict(block=BasicBlock, layers=[3, 4, 6, 3], **kwargs) - return _create_resnet('resnet34', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[3, 4, 6, 3]) + return _create_resnet('resnet34', pretrained, **dict(model_args, **kwargs)) @register_model def resnet34d(pretrained=False, **kwargs): """Constructs a ResNet-34-D model. """ - model_args = dict( - block=BasicBlock, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnet34d', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnet34d', pretrained, **dict(model_args, **kwargs)) @register_model def resnet26(pretrained=False, **kwargs): """Constructs a ResNet-26 model. """ - model_args = dict(block=Bottleneck, layers=[2, 2, 2, 2], **kwargs) - return _create_resnet('resnet26', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[2, 2, 2, 2]) + return _create_resnet('resnet26', pretrained, **dict(model_args, **kwargs)) @register_model def resnet26t(pretrained=False, **kwargs): """Constructs a ResNet-26-T model. """ - model_args = dict( - block=Bottleneck, layers=[2, 2, 2, 2], stem_width=32, stem_type='deep_tiered', avg_down=True, **kwargs) - return _create_resnet('resnet26t', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[2, 2, 2, 2], stem_width=32, stem_type='deep_tiered', avg_down=True) + return _create_resnet('resnet26t', pretrained, **dict(model_args, **kwargs)) @register_model def resnet26d(pretrained=False, **kwargs): """Constructs a ResNet-26-D model. """ - model_args = dict(block=Bottleneck, layers=[2, 2, 2, 2], stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnet26d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[2, 2, 2, 2], stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnet26d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -923,83 +918,79 @@ def resnet50(pretrained=False, **kwargs): """Constructs a ResNet-50 model. """ model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], **kwargs) - return _create_resnet('resnet50', pretrained, **model_args) + return _create_resnet('resnet50', pretrained, **dict(model_args, **kwargs)) @register_model def resnet50d(pretrained=False, **kwargs) -> ResNet: """Constructs a ResNet-50-D model. """ - model_args = dict( - block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnet50d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnet50d', pretrained, **dict(model_args, **kwargs)) @register_model def resnet50t(pretrained=False, **kwargs): """Constructs a ResNet-50-T model. """ - model_args = dict( - block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep_tiered', avg_down=True, **kwargs) - return _create_resnet('resnet50t', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep_tiered', avg_down=True) + return _create_resnet('resnet50t', pretrained, **dict(model_args, **kwargs)) @register_model def resnet101(pretrained=False, **kwargs): """Constructs a ResNet-101 model. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], **kwargs) - return _create_resnet('resnet101', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3]) + return _create_resnet('resnet101', pretrained, **dict(model_args, **kwargs)) @register_model def resnet101d(pretrained=False, **kwargs): """Constructs a ResNet-101-D model. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnet101d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnet101d', pretrained, **dict(model_args, **kwargs)) @register_model def resnet152(pretrained=False, **kwargs): """Constructs a ResNet-152 model. """ - model_args = dict(block=Bottleneck, layers=[3, 8, 36, 3], **kwargs) - return _create_resnet('resnet152', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 8, 36, 3]) + return _create_resnet('resnet152', pretrained, **dict(model_args, **kwargs)) @register_model def resnet152d(pretrained=False, **kwargs): """Constructs a ResNet-152-D model. """ - model_args = dict( - block=Bottleneck, layers=[3, 8, 36, 3], stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnet152d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 8, 36, 3], stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnet152d', pretrained, **dict(model_args, **kwargs)) @register_model def resnet200(pretrained=False, **kwargs): """Constructs a ResNet-200 model. """ - model_args = dict(block=Bottleneck, layers=[3, 24, 36, 3], **kwargs) - return _create_resnet('resnet200', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 24, 36, 3]) + return _create_resnet('resnet200', pretrained, **dict(model_args, **kwargs)) @register_model def resnet200d(pretrained=False, **kwargs): """Constructs a ResNet-200-D model. """ - model_args = dict( - block=Bottleneck, layers=[3, 24, 36, 3], stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnet200d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 24, 36, 3], stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnet200d', pretrained, **dict(model_args, **kwargs)) @register_model def tv_resnet34(pretrained=False, **kwargs): """Constructs a ResNet-34 model with original Torchvision weights. """ - model_args = dict(block=BasicBlock, layers=[3, 4, 6, 3], **kwargs) - return _create_resnet('tv_resnet34', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[3, 4, 6, 3]) + return _create_resnet('tv_resnet34', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1007,23 +998,23 @@ def tv_resnet50(pretrained=False, **kwargs): """Constructs a ResNet-50 model with original Torchvision weights. """ model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], **kwargs) - return _create_resnet('tv_resnet50', pretrained, **model_args) + return _create_resnet('tv_resnet50', pretrained, **dict(model_args, **kwargs)) @register_model def tv_resnet101(pretrained=False, **kwargs): """Constructs a ResNet-101 model w/ Torchvision pretrained weights. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], **kwargs) - return _create_resnet('tv_resnet101', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3]) + return _create_resnet('tv_resnet101', pretrained, **dict(model_args, **kwargs)) @register_model def tv_resnet152(pretrained=False, **kwargs): """Constructs a ResNet-152 model w/ Torchvision pretrained weights. """ - model_args = dict(block=Bottleneck, layers=[3, 8, 36, 3], **kwargs) - return _create_resnet('tv_resnet152', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 8, 36, 3]) + return _create_resnet('tv_resnet152', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1034,8 +1025,8 @@ def wide_resnet50_2(pretrained=False, **kwargs): convolutions is the same, e.g. last block in ResNet-50 has 2048-512-2048 channels, and in Wide ResNet-50-2 has 2048-1024-2048. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], base_width=128, **kwargs) - return _create_resnet('wide_resnet50_2', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], base_width=128) + return _create_resnet('wide_resnet50_2', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1045,8 +1036,8 @@ def wide_resnet101_2(pretrained=False, **kwargs): which is twice larger in every block. The number of channels in outer 1x1 convolutions is the same. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], base_width=128, **kwargs) - return _create_resnet('wide_resnet101_2', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], base_width=128) + return _create_resnet('wide_resnet101_2', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1061,8 +1052,8 @@ def resnet50_gn(pretrained=False, **kwargs): def resnext50_32x4d(pretrained=False, **kwargs): """Constructs a ResNeXt50-32x4d model. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4, **kwargs) - return _create_resnet('resnext50_32x4d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4) + return _create_resnet('resnext50_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1071,40 +1062,40 @@ def resnext50d_32x4d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4, - stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnext50d_32x4d', pretrained, **model_args) + stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnext50d_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model def resnext101_32x4d(pretrained=False, **kwargs): """Constructs a ResNeXt-101 32x4d model. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=4, **kwargs) - return _create_resnet('resnext101_32x4d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=4) + return _create_resnet('resnext101_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model def resnext101_32x8d(pretrained=False, **kwargs): """Constructs a ResNeXt-101 32x8d model. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8, **kwargs) - return _create_resnet('resnext101_32x8d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8) + return _create_resnet('resnext101_32x8d', pretrained, **dict(model_args, **kwargs)) @register_model def resnext101_64x4d(pretrained=False, **kwargs): """Constructs a ResNeXt101-64x4d model. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=64, base_width=4, **kwargs) - return _create_resnet('resnext101_64x4d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=64, base_width=4) + return _create_resnet('resnext101_64x4d', pretrained, **dict(model_args, **kwargs)) @register_model def tv_resnext50_32x4d(pretrained=False, **kwargs): """Constructs a ResNeXt50-32x4d model with original Torchvision weights. """ - model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4, **kwargs) - return _create_resnet('tv_resnext50_32x4d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4) + return _create_resnet('tv_resnext50_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1114,8 +1105,8 @@ def ig_resnext101_32x8d(pretrained=False, **kwargs): `"Exploring the Limits of Weakly Supervised Pretraining" `_ Weights from https://pytorch.org/hub/facebookresearch_WSL-Images_resnext/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8, **kwargs) - return _create_resnet('ig_resnext101_32x8d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8) + return _create_resnet('ig_resnext101_32x8d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1125,8 +1116,8 @@ def ig_resnext101_32x16d(pretrained=False, **kwargs): `"Exploring the Limits of Weakly Supervised Pretraining" `_ Weights from https://pytorch.org/hub/facebookresearch_WSL-Images_resnext/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=16, **kwargs) - return _create_resnet('ig_resnext101_32x16d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=16) + return _create_resnet('ig_resnext101_32x16d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1136,8 +1127,8 @@ def ig_resnext101_32x32d(pretrained=False, **kwargs): `"Exploring the Limits of Weakly Supervised Pretraining" `_ Weights from https://pytorch.org/hub/facebookresearch_WSL-Images_resnext/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=32, **kwargs) - return _create_resnet('ig_resnext101_32x32d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=32) + return _create_resnet('ig_resnext101_32x32d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1147,8 +1138,8 @@ def ig_resnext101_32x48d(pretrained=False, **kwargs): `"Exploring the Limits of Weakly Supervised Pretraining" `_ Weights from https://pytorch.org/hub/facebookresearch_WSL-Images_resnext/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=48, **kwargs) - return _create_resnet('ig_resnext101_32x48d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=48) + return _create_resnet('ig_resnext101_32x48d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1157,8 +1148,8 @@ def ssl_resnet18(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2], **kwargs) - return _create_resnet('ssl_resnet18', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2]) + return _create_resnet('ssl_resnet18', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1168,7 +1159,7 @@ def ssl_resnet50(pretrained=False, **kwargs): Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], **kwargs) - return _create_resnet('ssl_resnet50', pretrained, **model_args) + return _create_resnet('ssl_resnet50', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1177,8 +1168,8 @@ def ssl_resnext50_32x4d(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4, **kwargs) - return _create_resnet('ssl_resnext50_32x4d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4) + return _create_resnet('ssl_resnext50_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1187,8 +1178,8 @@ def ssl_resnext101_32x4d(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=4, **kwargs) - return _create_resnet('ssl_resnext101_32x4d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=4) + return _create_resnet('ssl_resnext101_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1197,8 +1188,8 @@ def ssl_resnext101_32x8d(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8, **kwargs) - return _create_resnet('ssl_resnext101_32x8d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8) + return _create_resnet('ssl_resnext101_32x8d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1207,8 +1198,8 @@ def ssl_resnext101_32x16d(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=16, **kwargs) - return _create_resnet('ssl_resnext101_32x16d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=16) + return _create_resnet('ssl_resnext101_32x16d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1218,8 +1209,8 @@ def swsl_resnet18(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2], **kwargs) - return _create_resnet('swsl_resnet18', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2]) + return _create_resnet('swsl_resnet18', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1230,7 +1221,7 @@ def swsl_resnet50(pretrained=False, **kwargs): Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], **kwargs) - return _create_resnet('swsl_resnet50', pretrained, **model_args) + return _create_resnet('swsl_resnet50', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1240,8 +1231,8 @@ def swsl_resnext50_32x4d(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4, **kwargs) - return _create_resnet('swsl_resnext50_32x4d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4) + return _create_resnet('swsl_resnext50_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1251,8 +1242,8 @@ def swsl_resnext101_32x4d(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=4, **kwargs) - return _create_resnet('swsl_resnext101_32x4d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=4) + return _create_resnet('swsl_resnext101_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1262,8 +1253,8 @@ def swsl_resnext101_32x8d(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8, **kwargs) - return _create_resnet('swsl_resnext101_32x8d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8) + return _create_resnet('swsl_resnext101_32x8d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1273,8 +1264,8 @@ def swsl_resnext101_32x16d(pretrained=False, **kwargs): `"Billion-scale Semi-Supervised Learning for Image Classification" `_ Weights from https://github.com/facebookresearch/semi-supervised-ImageNet1K-models/ """ - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=16, **kwargs) - return _create_resnet('swsl_resnext101_32x16d', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=16) + return _create_resnet('swsl_resnext101_32x16d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1285,8 +1276,8 @@ def ecaresnet26t(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[2, 2, 2, 2], stem_width=32, - stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnet26t', pretrained, **model_args) + stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnet26t', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1295,8 +1286,8 @@ def ecaresnet50d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnet50d', pretrained, **model_args) + block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnet50d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1306,7 +1297,7 @@ def ecaresnet50d_pruned(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='eca'), **kwargs) + block_args=dict(attn_layer='eca')) return _create_resnet('ecaresnet50d_pruned', pretrained, pruned=True, **model_args) @@ -1317,8 +1308,8 @@ def ecaresnet50t(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, - stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnet50t', pretrained, **model_args) + stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnet50t', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1327,8 +1318,8 @@ def ecaresnetlight(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[1, 1, 11, 3], stem_width=32, avg_down=True, - block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnetlight', pretrained, **model_args) + block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnetlight', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1337,8 +1328,8 @@ def ecaresnet101d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnet101d', pretrained, **model_args) + block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnet101d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1348,7 +1339,7 @@ def ecaresnet101d_pruned(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='eca'), **kwargs) + block_args=dict(attn_layer='eca')) return _create_resnet('ecaresnet101d_pruned', pretrained, pruned=True, **model_args) @@ -1358,8 +1349,8 @@ def ecaresnet200d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 24, 36, 3], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnet200d', pretrained, **model_args) + block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnet200d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1368,8 +1359,8 @@ def ecaresnet269d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 30, 48, 8], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnet269d', pretrained, **model_args) + block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnet269d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1380,8 +1371,8 @@ def ecaresnext26t_32x4d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[2, 2, 2, 2], cardinality=32, base_width=4, stem_width=32, - stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnext26t_32x4d', pretrained, **model_args) + stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnext26t_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1392,54 +1383,54 @@ def ecaresnext50t_32x4d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[2, 2, 2, 2], cardinality=32, base_width=4, stem_width=32, - stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='eca'), **kwargs) - return _create_resnet('ecaresnext50t_32x4d', pretrained, **model_args) + stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='eca')) + return _create_resnet('ecaresnext50t_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model def seresnet18(pretrained=False, **kwargs): - model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2], block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet18', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2], block_args=dict(attn_layer='se')) + return _create_resnet('seresnet18', pretrained, **dict(model_args, **kwargs)) @register_model def seresnet34(pretrained=False, **kwargs): - model_args = dict(block=BasicBlock, layers=[3, 4, 6, 3], block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet34', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[3, 4, 6, 3], block_args=dict(attn_layer='se')) + return _create_resnet('seresnet34', pretrained, **dict(model_args, **kwargs)) @register_model def seresnet50(pretrained=False, **kwargs): - model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet50', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], block_args=dict(attn_layer='se')) + return _create_resnet('seresnet50', pretrained, **dict(model_args, **kwargs)) @register_model def seresnet50t(pretrained=False, **kwargs): model_args = dict( - block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep_tiered', avg_down=True, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet50t', pretrained, **model_args) + block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep_tiered', + avg_down=True, block_args=dict(attn_layer='se')) + return _create_resnet('seresnet50t', pretrained, **dict(model_args, **kwargs)) @register_model def seresnet101(pretrained=False, **kwargs): - model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet101', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 23, 3], block_args=dict(attn_layer='se')) + return _create_resnet('seresnet101', pretrained, **dict(model_args, **kwargs)) @register_model def seresnet152(pretrained=False, **kwargs): - model_args = dict(block=Bottleneck, layers=[3, 8, 36, 3], block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet152', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 8, 36, 3], block_args=dict(attn_layer='se')) + return _create_resnet('seresnet152', pretrained, **dict(model_args, **kwargs)) @register_model def seresnet152d(pretrained=False, **kwargs): model_args = dict( - block=Bottleneck, layers=[3, 8, 36, 3], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet152d', pretrained, **model_args) + block=Bottleneck, layers=[3, 8, 36, 3], stem_width=32, stem_type='deep', + avg_down=True, block_args=dict(attn_layer='se')) + return _create_resnet('seresnet152d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1447,9 +1438,9 @@ def seresnet200d(pretrained=False, **kwargs): """Constructs a ResNet-200-D model with SE attn. """ model_args = dict( - block=Bottleneck, layers=[3, 24, 36, 3], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet200d', pretrained, **model_args) + block=Bottleneck, layers=[3, 24, 36, 3], stem_width=32, stem_type='deep', + avg_down=True, block_args=dict(attn_layer='se')) + return _create_resnet('seresnet200d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1457,9 +1448,9 @@ def seresnet269d(pretrained=False, **kwargs): """Constructs a ResNet-269-D model with SE attn. """ model_args = dict( - block=Bottleneck, layers=[3, 30, 48, 8], stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnet269d', pretrained, **model_args) + block=Bottleneck, layers=[3, 30, 48, 8], stem_width=32, stem_type='deep', + avg_down=True, block_args=dict(attn_layer='se')) + return _create_resnet('seresnet269d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1470,8 +1461,8 @@ def seresnext26d_32x4d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[2, 2, 2, 2], cardinality=32, base_width=4, stem_width=32, - stem_type='deep', avg_down=True, block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnext26d_32x4d', pretrained, **model_args) + stem_type='deep', avg_down=True, block_args=dict(attn_layer='se')) + return _create_resnet('seresnext26d_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1482,8 +1473,8 @@ def seresnext26t_32x4d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[2, 2, 2, 2], cardinality=32, base_width=4, stem_width=32, - stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnext26t_32x4d', pretrained, **model_args) + stem_type='deep_tiered', avg_down=True, block_args=dict(attn_layer='se')) + return _create_resnet('seresnext26t_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1499,24 +1490,24 @@ def seresnext26tn_32x4d(pretrained=False, **kwargs): def seresnext50_32x4d(pretrained=False, **kwargs): model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], cardinality=32, base_width=4, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnext50_32x4d', pretrained, **model_args) + block_args=dict(attn_layer='se')) + return _create_resnet('seresnext50_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model def seresnext101_32x4d(pretrained=False, **kwargs): model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=4, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnext101_32x4d', pretrained, **model_args) + block_args=dict(attn_layer='se')) + return _create_resnet('seresnext101_32x4d', pretrained, **dict(model_args, **kwargs)) @register_model def seresnext101_32x8d(pretrained=False, **kwargs): model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnext101_32x8d', pretrained, **model_args) + block_args=dict(attn_layer='se')) + return _create_resnet('seresnext101_32x8d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1524,32 +1515,32 @@ def seresnext101d_32x8d(pretrained=False, **kwargs): model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8, stem_width=32, stem_type='deep', avg_down=True, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnext101d_32x8d', pretrained, **model_args) + block_args=dict(attn_layer='se')) + return _create_resnet('seresnext101d_32x8d', pretrained, **dict(model_args, **kwargs)) @register_model def senet154(pretrained=False, **kwargs): model_args = dict( block=Bottleneck, layers=[3, 8, 36, 3], cardinality=64, base_width=4, stem_type='deep', - down_kernel_size=3, block_reduce_first=2, block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('senet154', pretrained, **model_args) + down_kernel_size=3, block_reduce_first=2, block_args=dict(attn_layer='se')) + return _create_resnet('senet154', pretrained, **dict(model_args, **kwargs)) @register_model def resnetblur18(pretrained=False, **kwargs): """Constructs a ResNet-18 model with blur anti-aliasing """ - model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2], aa_layer=BlurPool2d, **kwargs) - return _create_resnet('resnetblur18', pretrained, **model_args) + model_args = dict(block=BasicBlock, layers=[2, 2, 2, 2], aa_layer=BlurPool2d) + return _create_resnet('resnetblur18', pretrained, **dict(model_args, **kwargs)) @register_model def resnetblur50(pretrained=False, **kwargs): """Constructs a ResNet-50 model with blur anti-aliasing """ - model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], aa_layer=BlurPool2d, **kwargs) - return _create_resnet('resnetblur50', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], aa_layer=BlurPool2d) + return _create_resnet('resnetblur50', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1558,8 +1549,8 @@ def resnetblur50d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], aa_layer=BlurPool2d, - stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnetblur50d', pretrained, **model_args) + stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnetblur50d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1568,16 +1559,25 @@ def resnetblur101d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], aa_layer=BlurPool2d, - stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnetblur101d', pretrained, **model_args) + stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnetblur101d', pretrained, **dict(model_args, **kwargs)) + + +@register_model +def resnetaa34d(pretrained=False, **kwargs): + """Constructs a ResNet-34-D model w/ avgpool anti-aliasing + """ + model_args = dict( + block=BasicBlock, layers=[3, 4, 6, 3], aa_layer=nn.AvgPool2d, stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnetaa34d', pretrained, **dict(model_args, **kwargs)) @register_model def resnetaa50(pretrained=False, **kwargs): """Constructs a ResNet-50 model with avgpool anti-aliasing """ - model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], aa_layer=nn.AvgPool2d, **kwargs) - return _create_resnet('resnetaa50', pretrained, **model_args) + model_args = dict(block=Bottleneck, layers=[3, 4, 6, 3], aa_layer=nn.AvgPool2d) + return _create_resnet('resnetaa50', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1586,8 +1586,8 @@ def resnetaa50d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], aa_layer=nn.AvgPool2d, - stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnetaa50d', pretrained, **model_args) + stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnetaa50d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1596,8 +1596,8 @@ def resnetaa101d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], aa_layer=nn.AvgPool2d, - stem_width=32, stem_type='deep', avg_down=True, **kwargs) - return _create_resnet('resnetaa101d', pretrained, **model_args) + stem_width=32, stem_type='deep', avg_down=True) + return _create_resnet('resnetaa101d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1606,8 +1606,8 @@ def seresnetaa50d(pretrained=False, **kwargs): """ model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], aa_layer=nn.AvgPool2d, - stem_width=32, stem_type='deep', avg_down=True, block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnetaa50d', pretrained, **model_args) + stem_width=32, stem_type='deep', avg_down=True, block_args=dict(attn_layer='se')) + return _create_resnet('seresnetaa50d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1617,8 +1617,8 @@ def seresnextaa101d_32x8d(pretrained=False, **kwargs): model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], cardinality=32, base_width=8, stem_width=32, stem_type='deep', avg_down=True, aa_layer=nn.AvgPool2d, - block_args=dict(attn_layer='se'), **kwargs) - return _create_resnet('seresnextaa101d_32x8d', pretrained, **model_args) + block_args=dict(attn_layer='se')) + return _create_resnet('seresnextaa101d_32x8d', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1630,8 +1630,8 @@ def resnetrs50(pretrained=False, **kwargs): attn_layer = partial(get_attn('se'), rd_ratio=0.25) model_args = dict( block=Bottleneck, layers=[3, 4, 6, 3], stem_width=32, stem_type='deep', replace_stem_pool=True, - avg_down=True, block_args=dict(attn_layer=attn_layer), **kwargs) - return _create_resnet('resnetrs50', pretrained, **model_args) + avg_down=True, block_args=dict(attn_layer=attn_layer)) + return _create_resnet('resnetrs50', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1643,8 +1643,8 @@ def resnetrs101(pretrained=False, **kwargs): attn_layer = partial(get_attn('se'), rd_ratio=0.25) model_args = dict( block=Bottleneck, layers=[3, 4, 23, 3], stem_width=32, stem_type='deep', replace_stem_pool=True, - avg_down=True, block_args=dict(attn_layer=attn_layer), **kwargs) - return _create_resnet('resnetrs101', pretrained, **model_args) + avg_down=True, block_args=dict(attn_layer=attn_layer)) + return _create_resnet('resnetrs101', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1656,8 +1656,8 @@ def resnetrs152(pretrained=False, **kwargs): attn_layer = partial(get_attn('se'), rd_ratio=0.25) model_args = dict( block=Bottleneck, layers=[3, 8, 36, 3], stem_width=32, stem_type='deep', replace_stem_pool=True, - avg_down=True, block_args=dict(attn_layer=attn_layer), **kwargs) - return _create_resnet('resnetrs152', pretrained, **model_args) + avg_down=True, block_args=dict(attn_layer=attn_layer)) + return _create_resnet('resnetrs152', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1669,8 +1669,8 @@ def resnetrs200(pretrained=False, **kwargs): attn_layer = partial(get_attn('se'), rd_ratio=0.25) model_args = dict( block=Bottleneck, layers=[3, 24, 36, 3], stem_width=32, stem_type='deep', replace_stem_pool=True, - avg_down=True, block_args=dict(attn_layer=attn_layer), **kwargs) - return _create_resnet('resnetrs200', pretrained, **model_args) + avg_down=True, block_args=dict(attn_layer=attn_layer)) + return _create_resnet('resnetrs200', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1682,8 +1682,8 @@ def resnetrs270(pretrained=False, **kwargs): attn_layer = partial(get_attn('se'), rd_ratio=0.25) model_args = dict( block=Bottleneck, layers=[4, 29, 53, 4], stem_width=32, stem_type='deep', replace_stem_pool=True, - avg_down=True, block_args=dict(attn_layer=attn_layer), **kwargs) - return _create_resnet('resnetrs270', pretrained, **model_args) + avg_down=True, block_args=dict(attn_layer=attn_layer)) + return _create_resnet('resnetrs270', pretrained, **dict(model_args, **kwargs)) @@ -1696,8 +1696,8 @@ def resnetrs350(pretrained=False, **kwargs): attn_layer = partial(get_attn('se'), rd_ratio=0.25) model_args = dict( block=Bottleneck, layers=[4, 36, 72, 4], stem_width=32, stem_type='deep', replace_stem_pool=True, - avg_down=True, block_args=dict(attn_layer=attn_layer), **kwargs) - return _create_resnet('resnetrs350', pretrained, **model_args) + avg_down=True, block_args=dict(attn_layer=attn_layer)) + return _create_resnet('resnetrs350', pretrained, **dict(model_args, **kwargs)) @register_model @@ -1709,5 +1709,5 @@ def resnetrs420(pretrained=False, **kwargs): attn_layer = partial(get_attn('se'), rd_ratio=0.25) model_args = dict( block=Bottleneck, layers=[4, 44, 87, 4], stem_width=32, stem_type='deep', replace_stem_pool=True, - avg_down=True, block_args=dict(attn_layer=attn_layer), **kwargs) - return _create_resnet('resnetrs420', pretrained, **model_args) + avg_down=True, block_args=dict(attn_layer=attn_layer)) + return _create_resnet('resnetrs420', pretrained, **dict(model_args, **kwargs))