{"record":{"id":"f74974dfa68d00dd","repo":"open-mmlab/mmdetection","slug":"pretrained-must-be-a-str-or-none-f74974","errorCode":null,"errorMessage":"pretrained must be a str or None","messagePattern":"pretrained must be a str or None","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mmdet/models/backbones/hrnet.py","lineNumber":311,"sourceCode":"\n        self.pretrained = pretrained\n        assert not (init_cfg and pretrained), \\\n            'init_cfg and pretrained cannot be specified 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            if init_cfg is None:\n                self.init_cfg = [\n                    dict(type='Kaiming', layer='Conv2d'),\n                    dict(\n                        type='Constant',\n                        val=1,\n                        layer=['_BatchNorm', 'GroupNorm'])\n                ]\n        else:\n            raise TypeError('pretrained must be a str or None')\n\n        # Assert configurations of 4 stages are in extra\n        assert 'stage1' in extra and 'stage2' in extra \\\n               and 'stage3' in extra and 'stage4' in extra\n        # Assert whether the length of `num_blocks` and `num_channels` are\n        # equal to `num_branches`\n        for i in range(4):\n            cfg = extra[f'stage{i + 1}']\n            assert len(cfg['num_blocks']) == cfg['num_branches'] and \\\n                   len(cfg['num_channels']) == cfg['num_branches']\n\n        self.extra = extra\n        self.conv_cfg = conv_cfg\n        self.norm_cfg = norm_cfg\n        self.norm_eval = norm_eval\n        self.with_cp = with_cp\n        self.zero_init_residual = zero_init_residual\n","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/hrnet.py#L293-L329","documentation":"HRNet's legacy init path accepts pretrained only as a str path/URL or None; anything else (dict, list) raises TypeError('pretrained must be a str or None'). Like other mmdet backbones, HRNet has migrated to init_cfg-based weight loading.","triggerScenarios":"Passing pretrained=dict(checkpoint='...') to HRNet; passing a non-str object while also relying on the deprecated init_weights branch.","commonSituations":"Migrating MMDetection 1.x configs; mixing pretrained and init_cfg; script-generated configs embedding dicts.","solutions":["Use init_cfg=dict(type='Pretrained', checkpoint='open-mmlab://hrnetv2_w32') instead of pretrained","If pretrained is kept, pass a plain string or None","Remove stale pretrained keys when inheriting old base configs (use _delete_=True on the backbone dict)"],"exampleFix":"# before\nbackbone=dict(type='HRNet', pretrained='open-mmlab://hrnetv2_w32', extra=...)\n# after\nbackbone=dict(type='HRNet', init_cfg=dict(type='Pretrained', checkpoint='open-mmlab://hrnetv2_w32'), extra=...)","handlingStrategy":"type-guard","validationCode":"assert pretrained is None or isinstance(pretrained, str), 'HRNet pretrained must be str or None'","typeGuard":"def is_valid_pretrained(p) -> bool:\n    return p is None or isinstance(p, str)","tryCatchPattern":null,"preventionTips":["Use init_cfg=dict(type='Pretrained', checkpoint=...) instead","Remove legacy pretrained keys when inheriting old configs","Prefer open-mmlab:// prefix strings for bundled weights"],"tags":["mmdet","hrnet","pretrained-weights","init-cfg","migration"],"backgroundTag":null,"analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}