open-mmlab/mmdetection · error · TypeError
pretrained must be a str or None
Error message
pretrained must be a str or None
What it means
RegNet (inherits ResNet-style init) raises TypeError when the deprecated `pretrained` argument is not a str or None. Only a checkpoint path string or None is accepted; use init_cfg for new code.
Source
Thrown at mmdet/models/backbones/regnet.py:193
'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'])
]
if self.zero_init_residual:
block_init_cfg = dict(
type='Constant', val=0, override=dict(name='norm3'))
else:
raise TypeError('pretrained must be a str or None')
self.inplanes = stem_channels
self.res_layers = []
for i, num_blocks in enumerate(self.stage_blocks):
stride = self.strides[i]
dilation = self.dilations[i]
group_width = self.group_widths[i]
width = int(round(self.stage_widths[i] * self.bottleneck_ratio[i]))
stage_groups = width // group_width
dcn = self.dcn if self.stage_with_dcn[i] else None
if self.plugins is not None:
stage_plugins = self.make_stage_plugins(self.plugins, i)
else:
stage_plugins = None
res_layer = self.make_res_layer(
block=self.block,View on GitHub (pinned to cfd5d3a985)
Solutions
- Pass pretrained as a str checkpoint path or None
- Better: use init_cfg=dict(type='Pretrained', checkpoint='regnetx_400mf.pth') and drop pretrained
Example fix
// before backbone=dict(type='RegNet', arch='regnetx_400mf', pretrained='open-mmlab://regnetx_400mf') // after backbone=dict(type='RegNet', arch='regnetx_400mf', init_cfg=dict(type='Pretrained', checkpoint='regnetx_400mf_8xb128-...pth'))
Defensive patterns
Strategy: validation
Validate before calling
assert pretrained is None or isinstance(pretrained, str)
Prevention
- Standardize on init_cfg in all configs
- Assert type of pretrained when loading legacy configs
When it happens
Trigger: RegNet(pretrained=dict(...)) or pretrained=Path(...); mixing pretrained and init_cfg (which trips a separate assert).
Common situations: Porting old mmdet configs using pretrained='open-mmlab://detectron2/resnet50_caffe' style entries to RegNet; passing the whole init_cfg dict into the pretrained slot by mistake.
Related errors
- pretrained must be a str or None
- pretrained must be a str or None
- pretrained must be a str or None
- pretrained must be a str or None
- pretrained must be a str or None
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/634f788fc52d94f0.
Report an issue: GitHub.