{"record":{"id":"4247ba5b9e20e4bd","repo":"open-mmlab/mmdetection","slug":"pretrained-must-be-a-str-or-none-4247ba","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/roi_heads/shared_heads/res_layer.py","lineNumber":67,"sourceCode":"        self.add_module(f'layer{stage + 1}', res_layer)\n\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 a 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    def forward(self, x):\n        res_layer = getattr(self, f'layer{self.stage + 1}')\n        out = res_layer(x)\n        return out\n\n    def train(self, mode=True):\n        super(ResLayer, self).train(mode)\n        if self.norm_eval:\n            for m in self.modules():\n                if isinstance(m, nn.BatchNorm2d):\n                    m.eval()\n","sourceCodeStart":49,"sourceCodeEnd":80,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/roi_heads/shared_heads/res_layer.py#L49-L80","documentation":"ResLayer (shared head) accepts pretrained as either a str checkpoint path (converted into an init_cfg) or None; any other type raises TypeError in __init__.","triggerScenarios":"shared_head=dict(type='ResLayer', pretrained=123) or pretrained={'checkpoint': ...} or a list of paths.","commonSituations":"Old-style configs or code passing the newer init_cfg dict into pretrained; programmatic construction passing a Path object or bool.","solutions":["Pass a str path: pretrained='torchvision://resnet50' or a local .pth path string","Pass pretrained=None and use init_cfg=dict(type='Pretrained', checkpoint=...) instead","Convert Path objects with str(path) before passing"],"exampleFix":"# before\nshared_head=dict(type='ResLayer', pretrained={'ckpt': 'r50.pth'})\n# after\nshared_head=dict(type='ResLayer', pretrained='r50.pth')","handlingStrategy":"type-guard","validationCode":"p = cfg.get('pretrained', None)\nassert p is None or isinstance(p, str)","typeGuard":"def valid_pretrained(v) -> bool: return v is None or isinstance(v, str)","tryCatchPattern":null,"preventionTips":["Use init_cfg for new-style pretrained loading","str(Path) any checkpoint paths before passing"],"tags":["mmdetection","reslayer","shared-head","config"],"backgroundTag":"invalid-argument-type","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}