{"record":{"id":"28f26c8b9af31b55","repo":"open-mmlab/mmdetection","slug":"deprecationwarning-pretrained-is-a-deprecated-pl","errorCode":null,"errorMessage":"DeprecationWarning: pretrained is a deprecated, please use \"init_cfg\" instead","messagePattern":"DeprecationWarning: pretrained is a deprecated, please use \"init_cfg\" instead","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/models/roi_heads/shared_heads/res_layer.py","lineNumber":54,"sourceCode":"        inplanes = 64 * 2**(stage - 1) * block.expansion\n\n        res_layer = _ResLayer(\n            block,\n            inplanes,\n            planes,\n            stage_block,\n            stride=stride,\n            dilation=dilation,\n            style=style,\n            with_cp=with_cp,\n            norm_cfg=self.norm_cfg,\n            dcn=dcn)\n        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","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/roi_heads/shared_heads/res_layer.py#L36-L72","documentation":"Deprecation warning from ResLayer.__init__ (shared head): passing `pretrained='<checkpoint>'` is deprecated; the string is converted into init_cfg=dict(type='Pretrained', checkpoint=...). Specifying both pretrained and init_cfg raises an assertion instead.","triggerScenarios":"Building a shared ResLayer with pretrained='torchvision://resnet50' or similar; old Faster R-CNN configs that loaded backbone weights through the shared head's pretrained arg.","commonSituations":"Porting old two-stage detector configs to the init_cfg weight-loading scheme introduced in mmdet 2.x; mixing pretrained and init_cfg triggers the assert above.","solutions":["Replace pretrained='...' with init_cfg=dict(type='Pretrained', checkpoint='...')","Never set both pretrained and init_cfg (assertion error)","Remove pretrained if weights are already loaded by the detector's load_from"],"exampleFix":"# before\nshared_head=dict(type='ResLayer', depth=50, pretrained='torchvision://resnet50')\n# after\nshared_head=dict(type='ResLayer', depth=50, init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'))","handlingStrategy":"validation","validationCode":"assert 'pretrained' not in layer_cfg, 'use init_cfg=dict(type=\\'Pretrained\\', checkpoint=...)'; assert not ('pretrained' in layer_cfg and 'init_cfg' in layer_cfg)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never mix pretrained and init_cfg","Standardize on init_cfg for weight loading across the codebase"],"tags":["mmdet","deprecation","init-cfg","weights"],"backgroundTag":"deprecated-argument-migrated","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}