open-mmlab/mmdetection · warning
DeprecationWarning: pretrained is deprecated, please use "in
Error message
DeprecationWarning: pretrained is deprecated, please use "init_cfg" instead
What it means
Darknet backbone __init__ warns that the 'pretrained' string argument is deprecated in favor of 'init_cfg'. The model still builds — the checkpoint is converted into init_cfg=dict(type='Pretrained', checkpoint=...) — but the old API may be removed later.
Source
Thrown at mmdet/models/backbones/darknet.py:138
cfg = dict(conv_cfg=conv_cfg, norm_cfg=norm_cfg, act_cfg=act_cfg)
self.conv1 = ConvModule(3, 32, 3, padding=1, **cfg)
self.cr_blocks = ['conv1']
for i, n_layers in enumerate(self.layers):
layer_name = f'conv_res_block{i + 1}'
in_c, out_c = self.channels[i]
self.add_module(
layer_name,
self.make_conv_res_block(in_c, out_c, n_layers, **cfg))
self.cr_blocks.append(layer_name)
self.norm_eval = norm_eval
assert not (init_cfg and pretrained), \
'init_cfg and pretrained cannot be specified at the same time'
if isinstance(pretrained, str):
warnings.warn('DeprecationWarning: pretrained is deprecated, '
'please use "init_cfg" instead')
self.init_cfg = dict(type='Pretrained', checkpoint=pretrained)
elif pretrained is None:
if init_cfg is None:
self.init_cfg = [
dict(type='Kaiming', layer='Conv2d'),
dict(
type='Constant',
val=1,
layer=['_BatchNorm', 'GroupNorm'])
]
else:
raise TypeError('pretrained must be a str or None')
def forward(self, x):
outs = []
for i, layer_name in enumerate(self.cr_blocks):
cr_block = getattr(self, layer_name)View on GitHub (pinned to cfd5d3a985)
Solutions
- Replace pretrained='path_or_url' with init_cfg=dict(type='Pretrained', checkpoint='path_or_url') in the backbone config
- Note both cannot be set simultaneously (assertion forbids init_cfg + pretrained together)
- Update any saved config pipelines/scripts that generate model dicts
Example fix
# before model = dict(backbone=dict(type='Darknet', pretrained='open-mmlab://darknet53')) # after model = dict(backbone=dict(type='Darknet', init_cfg=dict(type='Pretrained', checkpoint='open-mmlab://darknet53')))
Defensive patterns
Strategy: validation
Validate before calling
cfg = dict(type='Darknet') assert 'pretrained' not in cfg, 'use init_cfg instead of pretrained'
Prevention
- Prefer init_cfg in all new configs
- Lint configs for deprecated pretrained keys
- Never combine pretrained with init_cfg (assertion error)
When it happens
Trigger: Instantiating Darknet(pretrained='open-mmlab://darknet53') or a config using pretrained=... in model backbone init args.
Common situations: Old MMDetection 2.x configs or tutorials passed backbone=dict(type='Darknet', pretrained='...'). New configs should use init_cfg.
Related errors
- invalid depth {depth} for darknet
- pretrained must be a str or None
- frozen_stages must be in range(-1, len(arch_setting) + 1). B
- frozen_stages must be in range(-1, len(arch_setting) + 1). B
- `init_cfg` must contain the key "type"
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/3451dcee7d2106c0.
Report an issue: GitHub.