Skip to content

Commit

Permalink
Merge pull request huggingface#413 from rwightman/eca-weights
Browse files Browse the repository at this point in the history
Add new weights for ecaresnet26t/50t/269d models.
  • Loading branch information
rwightman authored Feb 8, 2021
2 parents b608c05 + 28183d9 commit 048026d
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 132 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## What's New

### Feb 8, 2021
* Add several ResNet weights with ECA attention. 26t & 50t trained @ 256, test @ 320. 269d train @ 256, fine-tune @320, test @ 352.
* `ecaresnet26t` - 79.88 top-1 @ 320x320, 79.08 @ 256x256
* `ecaresnet50t` - 82.35 top-1 @ 320x320, 81.52 @ 256x256
* `ecaresnet269d` - 84.93 top-1 @ 352x352, 84.87 @ 320x320
* Remove separate tiered (`t`) vs tiered_narrow (`tn`) ResNet model defs, all `tn` changed to `t` and `t` models removed (`seresnext26t_32x4d` only model w/ weights that was removed).
* Support model default_cfgs with separate train vs test resolution `test_input_size`

### Jan 30, 2021
* Add initial "Normalization Free" NF-RegNet-B* and NF-ResNet model definitions based on [paper](https://arxiv.org/abs/2101.08692)

Expand Down
2 changes: 0 additions & 2 deletions sotabench.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def _entry(model_name, paper_model_name, paper_arxiv_id, batch_size=BATCH_SIZE,
model_desc='Block cfg of SE-ResNeXt-34 w/ Bottleneck, deep stem, and avg-pool in downsample layers.'),
_entry('seresnext26t_32x4d', 'SE-ResNeXt-26-T 32x4d', '1812.01187',
model_desc='Block cfg of SE-ResNeXt-34 w/ Bottleneck, deep tiered stem, and avg-pool in downsample layers.'),
_entry('seresnext26tn_32x4d', 'SE-ResNeXt-26-TN 32x4d', '1812.01187',
model_desc='Block cfg of SE-ResNeXt-34 w/ Bottleneck, deep tiered narrow stem, and avg-pool in downsample layers.'),
_entry('seresnext50_32x4d', 'SE-ResNeXt-50 32x4d', '1709.01507'),

_entry('skresnet18', 'SK-ResNet-18', '1903.06586'),
Expand Down
9 changes: 6 additions & 3 deletions timm/data/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
_logger = logging.getLogger(__name__)


def resolve_data_config(args, default_cfg={}, model=None, verbose=True):
def resolve_data_config(args, default_cfg={}, model=None, use_test_size=False, verbose=True):
new_config = {}
default_cfg = default_cfg
if not default_cfg and model is not None and hasattr(model, 'default_cfg'):
Expand All @@ -25,8 +25,11 @@ def resolve_data_config(args, default_cfg={}, model=None, verbose=True):
elif 'img_size' in args and args['img_size'] is not None:
assert isinstance(args['img_size'], int)
input_size = (in_chans, args['img_size'], args['img_size'])
elif 'input_size' in default_cfg:
input_size = default_cfg['input_size']
else:
if use_test_size and 'test_input_size' in default_cfg:
input_size = default_cfg['test_input_size']
elif 'input_size' in default_cfg:
input_size = default_cfg['input_size']
new_config['input_size'] = input_size

# resolve interpolation method
Expand Down
6 changes: 3 additions & 3 deletions timm/models/efficientnet_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ def __init__(self, in_chs, out_chs, exp_kernel_size=3, exp_ratio=1.0, fake_in_ch
self.drop_path_rate = drop_path_rate

# Expansion convolution
self.conv_exp = create_conv2d(in_chs, mid_chs, exp_kernel_size, padding=pad_type)
self.conv_exp = create_conv2d(
in_chs, mid_chs, exp_kernel_size, stride=stride, dilation=dilation, padding=pad_type)
self.bn1 = norm_layer(mid_chs, **norm_kwargs)
self.act1 = act_layer(inplace=True)

Expand All @@ -362,8 +363,7 @@ def __init__(self, in_chs, out_chs, exp_kernel_size=3, exp_ratio=1.0, fake_in_ch
self.se = None

# Point-wise linear projection
self.conv_pwl = create_conv2d(
mid_chs, out_chs, pw_kernel_size, stride=stride, dilation=dilation, padding=pad_type)
self.conv_pwl = create_conv2d(mid_chs, out_chs, pw_kernel_size, padding=pad_type)
self.bn2 = norm_layer(out_chs, **norm_kwargs)

def feature_info(self, location):
Expand Down
11 changes: 7 additions & 4 deletions timm/models/layers/test_time_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ def forward(self, x):
return x.view(x.size(0), -1)


def apply_test_time_pool(model, config):
def apply_test_time_pool(model, config, use_test_size=True):
test_time_pool = False
if not hasattr(model, 'default_cfg') or not model.default_cfg:
return model, False
if (config['input_size'][-1] > model.default_cfg['input_size'][-1] and
config['input_size'][-2] > model.default_cfg['input_size'][-2]):
if use_test_size and 'test_input_size' in model.default_cfg:
df_input_size = model.default_cfg['test_input_size']
else:
df_input_size = model.default_cfg['input_size']
if config['input_size'][-1] > df_input_size[-1] and config['input_size'][-2] > df_input_size[-2]:
_logger.info('Target input size %s > pretrained default %s, using test time pooling' %
(str(config['input_size'][-2:]), str(model.default_cfg['input_size'][-2:])))
(str(config['input_size'][-2:]), str(df_input_size[-2:])))
model = TestTimePoolHead(model, original_pool=model.default_cfg['pool_size'])
test_time_pool = True
return model, test_time_pool
Loading

0 comments on commit 048026d

Please sign in to comment.