{"record":{"id":"24c9c631f2e58fb5","repo":"open-mmlab/mmdetection","slug":"pretrained-must-be-a-str-or-none-24c9c6","errorCode":null,"errorMessage":"pretrained must be a str or None","messagePattern":"pretrained must be a str or None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mmdet/models/backbones/resnet.py","lineNumber":426,"sourceCode":"                    dict(\n                        type='Constant',\n                        val=1,\n                        layer=['_BatchNorm', 'GroupNorm'])\n                ]\n                block = self.arch_settings[depth][0]\n                if self.zero_init_residual:\n                    if block is BasicBlock:\n                        block_init_cfg = dict(\n                            type='Constant',\n                            val=0,\n                            override=dict(name='norm2'))\n                    elif block is Bottleneck:\n                        block_init_cfg = dict(\n                            type='Constant',\n                            val=0,\n                            override=dict(name='norm3'))\n        else:\n            raise TypeError('pretrained must be a str or None')\n\n        self.depth = depth\n        if stem_channels is None:\n            stem_channels = base_channels\n        self.stem_channels = stem_channels\n        self.base_channels = base_channels\n        self.num_stages = num_stages\n        assert num_stages >= 1 and num_stages <= 4\n        self.strides = strides\n        self.dilations = dilations\n        assert len(strides) == len(dilations) == num_stages\n        self.out_indices = out_indices\n        assert max(out_indices) < num_stages\n        self.style = style\n        self.deep_stem = deep_stem\n        self.avg_down = avg_down\n        self.frozen_stages = frozen_stages\n        self.conv_cfg = conv_cfg","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/resnet.py#L408-L444","documentation":"ResNet.__init__ raises TypeError when the deprecated `pretrained` is neither a str nor None. A str becomes init_cfg=dict(type='Pretrained', ...); None means use init_cfg; other types are rejected, and passing both init_cfg and pretrained trips an assert.","triggerScenarios":"ResNet(pretrained=dict(type='Pretrained', checkpoint=...)); ResNet(pretrained=True); combining pretrained and init_cfg.","commonSituations":"Legacy configs from mmdet v1/v2 using pretrained='torchvision://resnet50'; converting configs and leaving both keys; passing a loaded state_dict object instead of a path.","solutions":["Use init_cfg=dict(type='Pretrained', checkpoint='...') and remove pretrained","If keeping pretrained, pass only a str path and remove init_cfg","Pass a Path to a checkpoint file, not a loaded state_dict"],"exampleFix":"// before\nbackbone=dict(type='ResNet', depth=50, pretrained='torchvision://resnet50', init_cfg=None)\n// after\nbackbone=dict(type='ResNet', depth=50, init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'))","handlingStrategy":"validation","validationCode":"assert not (init_cfg and pretrained), 'cannot set both'\\nassert pretrained is None or isinstance(pretrained, str)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Migrate configs to init_cfg","Run a config lint step in CI that rejects pretrained alongside init_cfg"],"tags":["mmdet","resnet","pretrained","init-cfg","deprecation"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}