From 01cb46a9a50e3ba4be167965b5764e9702f09b30 Mon Sep 17 00:00:00 2001 From: Ross Wightman Date: Sat, 7 Aug 2021 16:45:29 -0700 Subject: [PATCH] Add gc_efficientnetv2_rw_t weights (global context instead of SE attn). Add TF XL weights even though the fine-tuned ones don't validate that well. Change default arg for GlobalContext to use scal (mul) mode. --- tests/test_models.py | 2 +- timm/models/efficientnet.py | 31 +++------------------------- timm/models/layers/global_context.py | 2 +- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index b7bd1431..50838c8a 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -25,7 +25,7 @@ if 'GITHUB_ACTIONS' in os.environ: # and 'Linux' in platform.system(): # GitHub Linux runner is slower and hits memory limits sooner than MacOS, exclude bigger models EXCLUDE_FILTERS = [ '*efficientnet_l2*', '*resnext101_32x48d', '*in21k', '*152x4_bitm', '*101x3_bitm', '*50x3_bitm', - '*nfnet_f3*', '*nfnet_f4*', '*nfnet_f5*', '*nfnet_f6*', '*nfnet_f7*', + '*nfnet_f3*', '*nfnet_f4*', '*nfnet_f5*', '*nfnet_f6*', '*nfnet_f7*', '*efficientnetv2_xl*', '*resnetrs350*', '*resnetrs420*', 'xcit_large_24_p8*'] else: EXCLUDE_FILTERS = [] diff --git a/timm/models/efficientnet.py b/timm/models/efficientnet.py index 6e14ab61..6b8c0473 100644 --- a/timm/models/efficientnet.py +++ b/timm/models/efficientnet.py @@ -92,11 +92,6 @@ default_cfgs = { interpolation='bilinear'), # NOTE experimenting with alternate attention - 'eca_efficientnet_b0': _cfg( - url=''), - 'gc_efficientnet_b0': _cfg( - url=''), - 'efficientnet_b0': _cfg( url='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/efficientnet_b0_ra-3dd342df.pth'), 'efficientnet_b1': _cfg( @@ -169,7 +164,7 @@ default_cfgs = { url='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/efficientnetv2_t_agc-3620981a.pth', input_size=(3, 224, 224), test_input_size=(3, 288, 288), pool_size=(7, 7), crop_pct=1.0), 'gc_efficientnetv2_rw_t': _cfg( - url='', + url='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/gc_efficientnetv2_rw_t_agc-927a0bde.pth', input_size=(3, 224, 224), test_input_size=(3, 288, 288), pool_size=(7, 7), crop_pct=1.0), 'efficientnetv2_rw_s': _cfg( url='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/efficientnet_v2s_ra2_288-a6477665.pth', @@ -362,7 +357,7 @@ default_cfgs = { mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5), input_size=(3, 384, 384), test_input_size=(3, 480, 480), pool_size=(12, 12), crop_pct=1.0), 'tf_efficientnetv2_xl_in21ft1k': _cfg( - url='', + url='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-effv2-weights/tf_efficientnetv2_xl_in21ft1k-06c35c48.pth', mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5), input_size=(3, 384, 384), test_input_size=(3, 512, 512), pool_size=(12, 12), crop_pct=1.0), @@ -379,7 +374,7 @@ default_cfgs = { mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5), num_classes=21843, input_size=(3, 384, 384), test_input_size=(3, 480, 480), pool_size=(12, 12), crop_pct=1.0), 'tf_efficientnetv2_xl_in21k': _cfg( - url='', + url='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-effv2-weights/tf_efficientnetv2_xl_in21k-fd7e8abf.pth', mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5), num_classes=21843, input_size=(3, 384, 384), test_input_size=(3, 512, 512), pool_size=(12, 12), crop_pct=1.0), @@ -1276,26 +1271,6 @@ def efficientnet_b0(pretrained=False, **kwargs): return model -@register_model -def eca_efficientnet_b0(pretrained=False, **kwargs): - """ EfficientNet-B0 w/ ECA attn """ - # NOTE experimental config - model = _gen_efficientnet( - 'eca_efficientnet_b0', se_layer='ecam', channel_multiplier=1.0, depth_multiplier=1.0, - pretrained=pretrained, **kwargs) - return model - - -@register_model -def gc_efficientnet_b0(pretrained=False, **kwargs): - """ EfficientNet-B0 w/ GlobalContext """ - # NOTE experminetal config - model = _gen_efficientnet( - 'gc_efficientnet_b0', se_layer='gc', channel_multiplier=1.0, depth_multiplier=1.0, - pretrained=pretrained, **kwargs) - return model - - @register_model def efficientnet_b1(pretrained=False, **kwargs): """ EfficientNet-B1 """ diff --git a/timm/models/layers/global_context.py b/timm/models/layers/global_context.py index 4c2c82f3..de7fb5c1 100644 --- a/timm/models/layers/global_context.py +++ b/timm/models/layers/global_context.py @@ -18,7 +18,7 @@ from .norm import LayerNorm2d class GlobalContext(nn.Module): - def __init__(self, channels, use_attn=True, fuse_add=True, fuse_scale=False, init_last_zero=False, + def __init__(self, channels, use_attn=True, fuse_add=False, fuse_scale=True, init_last_zero=False, rd_ratio=1./8, rd_channels=None, rd_divisor=1, act_layer=nn.ReLU, gate_layer='sigmoid'): super(GlobalContext, self).__init__() act_layer = get_act_layer(act_layer)