{"record":{"id":"8dca95f16cc470c6","repo":"open-mmlab/mmdetection","slug":"pretrained-must-be-a-str-or-none-8dca95","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/pvt.py","lineNumber":457,"sourceCode":"        if isinstance(pretrain_img_size, int):\n            pretrain_img_size = to_2tuple(pretrain_img_size)\n        elif isinstance(pretrain_img_size, tuple):\n            if len(pretrain_img_size) == 1:\n                pretrain_img_size = to_2tuple(pretrain_img_size[0])\n            assert len(pretrain_img_size) == 2, \\\n                f'The size of image should have length 1 or 2, ' \\\n                f'but got {len(pretrain_img_size)}'\n\n        assert not (init_cfg and pretrained), \\\n            'init_cfg and pretrained cannot be setting at the same time'\n        if isinstance(pretrained, str):\n            warnings.warn('DeprecationWarning: pretrained is deprecated, '\n                          'please use \"init_cfg\" instead')\n            self.init_cfg = dict(type='Pretrained', checkpoint=pretrained)\n        elif pretrained is None:\n            self.init_cfg = init_cfg\n        else:\n            raise TypeError('pretrained must be a str or None')\n\n        self.embed_dims = embed_dims\n\n        self.num_stages = num_stages\n        self.num_layers = num_layers\n        self.num_heads = num_heads\n        self.patch_sizes = patch_sizes\n        self.strides = strides\n        self.sr_ratios = sr_ratios\n        assert num_stages == len(num_layers) == len(num_heads) \\\n               == len(patch_sizes) == len(strides) == len(sr_ratios)\n\n        self.out_indices = out_indices\n        assert max(out_indices) < self.num_stages\n        self.pretrained = pretrained\n\n        # transformer encoder\n        dpr = [","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/pvt.py#L439-L475","documentation":"PyramidVisionTransformer (PVT) __init__ raises TypeError when the deprecated `pretrained` argument is not a str or None. A str is wrapped into init_cfg=dict(type='Pretrained', checkpoint=...); None defers to init_cfg. Anything else is invalid.","triggerScenarios":"PVT(pretrained=dict(...)) or pretrained=Path('pvt.pth'); combining pretrained with an explicit init_cfg.","commonSituations":"Migrating old configs to the init_cfg API; passing a config dict where a checkpoint path string was expected.","solutions":["Pass pretrained as a checkpoint path string, or preferably use init_cfg=dict(type='Pretrained', checkpoint='...')","Do not pass both pretrained and init_cfg simultaneously"],"exampleFix":"// before\nbackbone=dict(type='PyramidVisionTransformer', pretrained=dict(type='Pretrained'))\n// after\nbackbone=dict(type='PyramidVisionTransformer', init_cfg=dict(type='Pretrained', checkpoint='pvt_small.pth'))","handlingStrategy":"validation","validationCode":"assert pretrained is None or isinstance(pretrained, str)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use init_cfg API exclusively in new configs","Never pass both pretrained and init_cfg"],"tags":["mmdet","pvt","pretrained","init-cfg","config"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}