{"record":{"id":"ae378de9e0c2c55f","repo":"open-mmlab/mmdetection","slug":"pretrained-must-be-a-str-or-none-ae378d","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/mobilenet_v2.py","lineNumber":77,"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        self.widen_factor = widen_factor\n        self.out_indices = out_indices\n        if not set(out_indices).issubset(set(range(0, 8))):\n            raise ValueError('out_indices must be a subset of range'\n                             f'(0, 8). But received {out_indices}')\n\n        if frozen_stages not in range(-1, 8):\n            raise ValueError('frozen_stages must be in range(-1, 8). '\n                             f'But received {frozen_stages}')\n        self.out_indices = out_indices\n        self.frozen_stages = frozen_stages\n        self.conv_cfg = conv_cfg\n        self.norm_cfg = norm_cfg\n        self.act_cfg = act_cfg\n        self.norm_eval = norm_eval\n        self.with_cp = with_cp\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/mobilenet_v2.py#L59-L95","documentation":"MobileNetV2.__init__ throws TypeError when the deprecated `pretrained` argument is neither a str nor None. The constructor accepts pretrained only as a checkpoint path string (converted to init_cfg) or None; any other type (dict, bool, list) is rejected. New configs should use init_cfg instead.","triggerScenarios":"Calling MobileNetV2(pretrained=dict(checkpoint=...)) or passing a Path/bool/list as pretrained; mixing old-style pretrained configs with new init_cfg usage.","commonSituations":"Migrating old mmdet v1/v2 configs that used pretrained='open-mmlab://...' or pretrained=dict(...); copy-pasting configs across mmdet versions where pretrained semantics changed.","solutions":["Use init_cfg instead: MobileNetV2(init_cfg=dict(type='Pretrained', checkpoint='mobilenet_v2_8xb32_cifar10...'))","If using pretrained, pass a str URL/path or None only","Remove duplicate init_cfg when passing pretrained as str (they cannot be combined)"],"exampleFix":"// before\nmodel = dict(backbone=dict(type='MobileNetV2', pretrained=dict(type='Pretrained', checkpoint='...')))\n// after\nmodel = dict(backbone=dict(type='MobileNetV2', init_cfg=dict(type='Pretrained', checkpoint='...')))","handlingStrategy":"validation","validationCode":"assert pretrained is None or isinstance(pretrained, str), 'pretrained must be str or None'","typeGuard":"def is_valid_pretrained(p) -> bool:\\n    return p is None or (isinstance(p, str) and len(p) > 0)","tryCatchPattern":null,"preventionTips":["Prefer init_cfg over pretrained in all new configs","Validate pretrained type before building the backbone"],"tags":["mmdet","mobilenetv2","config","init-cfg","pretrained"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}