open-mmlab/mmdetection · error · TypeError
pretrained must be a str or None
Error message
pretrained must be a str or None
What it means
SSDVGG.__init__ raises TypeError when the deprecated `pretrained` is neither a str nor None. Like other mmdet backbones, str is converted to init_cfg and new code should use init_cfg directly.
Source
Thrown at mmdet/models/backbones/ssd_vgg.py:97
self.out_feature_indices = out_feature_indices
assert not (init_cfg and pretrained), \
'init_cfg and pretrained cannot be specified at the same time'
if init_cfg is not None:
self.init_cfg = init_cfg
elif 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:
self.init_cfg = [
dict(type='Kaiming', layer='Conv2d'),
dict(type='Constant', val=1, layer='BatchNorm2d'),
dict(type='Normal', std=0.01, layer='Linear'),
]
else:
raise TypeError('pretrained must be a str or None')
if input_size is not None:
warnings.warn('DeprecationWarning: input_size is deprecated')
if l2_norm_scale is not None:
warnings.warn('DeprecationWarning: l2_norm_scale in VGG is '
'deprecated, it has been moved to SSDNeck.')
def init_weights(self, pretrained=None):
super(VGG, self).init_weights()
def forward(self, x):
"""Forward function."""
outs = []
for i, layer in enumerate(self.features):
x = layer(x)
if i in self.out_feature_indices:
outs.append(x)
View on GitHub (pinned to cfd5d3a985)
Solutions
- Use init_cfg=dict(type='Pretrained', checkpoint='vgg16_caffe-...pth')
- Or pass pretrained as a checkpoint path string only
Example fix
// before backbone=dict(type='SSDVGG', depth=16, pretrained='open-mmlab://vgg16_caffe') // after backbone=dict(type='SSDVGG', depth=16, with_last_pool=False, init_cfg=dict(type='Pretrained', checkpoint='vgg16_caffe-...pth'))
Defensive patterns
Strategy: validation
Validate before calling
assert pretrained is None or isinstance(pretrained, str)
Prevention
- Use init_cfg for checkpoint loading
- Keep deprecated pretrained only as a str path
When it happens
Trigger: SSDVGG(pretrained=dict(checkpoint=...)) or pretrained=Path; also triggered by passing pretrained alongside init_cfg in older code paths.
Common situations: Old SSD configs (v1-era) using pretrained='open-mmlab://vgg16_caffe'; migrating SSD pipelines to the init_cfg API.
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/bfe04aeb08510db2.
Report an issue: GitHub.