Skip to content

Commit a9f9148

Browse files
committed
Fix #1078, DarkNet has 6 feature maps. Make vgg and darknet out_indices handling/comments equivalent
1 parent c21b216 commit a9f9148

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

timm/models/cspnet.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,14 @@ 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))
411414
return build_model_with_cfg(
412415
CspNet, variant, pretrained,
413416
default_cfg=default_cfgs[variant],
414-
feature_cfg=dict(flatten_sequential=True), model_cfg=model_cfgs[cfg_variant],
417+
model_cfg=model_cfgs[cfg_variant],
418+
feature_cfg=dict(flatten_sequential=True),
415419
**kwargs)
416420

417421

timm/models/vgg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ def _filter_fn(state_dict):
179179

180180
def _create_vgg(variant: str, pretrained: bool, **kwargs: Any) -> VGG:
181181
cfg = variant.split('_')[0]
182-
# NOTE: VGG is one of the only models with stride==1 features, so indices are offset from other models
183-
out_indices = kwargs.get('out_indices', (0, 1, 2, 3, 4, 5))
182+
# 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))
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, out_indices=out_indices),
188+
feature_cfg=dict(flatten_sequential=True),
189189
pretrained_filter_fn=_filter_fn,
190190
**kwargs)
191191
return model

0 commit comments

Comments
 (0)