Skip to content

Commit a09c88e

Browse files
committed
Support other features only modes for EfficientNet
1 parent 2d597b1 commit a09c88e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

timm/models/_efficientnet_builder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,11 @@ def __call__(self, in_chs, model_block_args):
419419
if extract_features:
420420
feature_info = dict(
421421
stage=stack_idx + 1, reduction=current_stride, **block.feature_info(self.feature_location))
422-
module_name = f'blocks.{stack_idx}.{block_idx}'
423422
leaf_name = feature_info.get('module', '')
424-
feature_info['module'] = '.'.join([module_name, leaf_name]) if leaf_name else module_name
423+
if leaf_name:
424+
feature_info['module'] = '.'.join([f'blocks.{stack_idx}.{block_idx}', leaf_name])
425+
else:
426+
feature_info['module'] = f'blocks.{stack_idx}'
425427
self.features.append(feature_info)
426428

427429
total_block_idx += 1 # incr global block idx (across all stacks)

timm/models/efficientnet.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,20 @@ def forward(self, x) -> List[torch.Tensor]:
269269

270270
def _create_effnet(variant, pretrained=False, **kwargs):
271271
features_only = False
272+
features_cls = False
272273
model_cls = EfficientNet
273274
kwargs_filter = None
274275
if kwargs.pop('features_only', False):
275-
features_only = True
276-
kwargs_filter = ('num_classes', 'num_features', 'head_conv', 'global_pool')
277-
model_cls = EfficientNetFeatures
276+
if 'feature_cfg' not in kwargs:
277+
kwargs_filter = ('num_classes', 'num_features', 'head_conv', 'global_pool')
278+
model_cls = EfficientNetFeatures
279+
features_cls = True
280+
else:
281+
features_only = True
278282
model = build_model_with_cfg(
279283
model_cls, variant, pretrained,
280-
pretrained_strict=not features_only,
284+
features_only=features_only,
285+
pretrained_strict=not features_cls,
281286
kwargs_filter=kwargs_filter,
282287
**kwargs)
283288
if features_only:

0 commit comments

Comments
 (0)