Skip to content

Commit ccfeb06

Browse files
committed
Fix out_indices handling breakage, should have left as per vgg approach.
1 parent a9f9148 commit ccfeb06

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

timm/models/cspnet.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,13 @@ def forward(self, x):
408408

409409
def _create_cspnet(variant, pretrained=False, **kwargs):
410410
cfg_variant = variant.split('_')[0]
411-
if 'darknet' in variant:
412-
# NOTE: DarkNet is one of few models with stride==1 features w/ 6 out_indices [0..5]
413-
kwargs.setdefault('out_indices', (0, 1, 2, 3, 4, 5))
411+
# NOTE: DarkNet is one of few models with stride==1 features w/ 6 out_indices [0..5]
412+
out_indices = kwargs.get('out_indices', (0, 1, 2, 3, 4, 5) if 'darknet' in variant else (0, 1, 2, 3, 4))
414413
return build_model_with_cfg(
415414
CspNet, variant, pretrained,
416415
default_cfg=default_cfgs[variant],
417416
model_cfg=model_cfgs[cfg_variant],
418-
feature_cfg=dict(flatten_sequential=True),
417+
feature_cfg=dict(flatten_sequential=True, out_indices=out_indices),
419418
**kwargs)
420419

421420

timm/models/vgg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ def _filter_fn(state_dict):
180180
def _create_vgg(variant: str, pretrained: bool, **kwargs: Any) -> VGG:
181181
cfg = variant.split('_')[0]
182182
# NOTE: VGG is one of few models with stride==1 features w/ 6 out_indices [0..5]
183-
kwargs.setdefault('out_indices', (0, 1, 2, 3, 4, 5))
183+
out_indices = kwargs.get('out_indices', (0, 1, 2, 3, 4, 5))
184184
model = build_model_with_cfg(
185185
VGG, variant, pretrained,
186186
default_cfg=default_cfgs[variant],
187187
model_cfg=cfgs[cfg],
188-
feature_cfg=dict(flatten_sequential=True),
188+
feature_cfg=dict(flatten_sequential=True, out_indices=out_indices),
189189
pretrained_filter_fn=_filter_fn,
190190
**kwargs)
191191
return model

0 commit comments

Comments
 (0)