{"record":{"id":"3451dcee7d2106c0","repo":"open-mmlab/mmdetection","slug":"deprecationwarning-pretrained-is-deprecated-plea","errorCode":null,"errorMessage":"DeprecationWarning: pretrained is deprecated, please use \"init_cfg\" instead","messagePattern":"DeprecationWarning: pretrained is deprecated, please use \"init_cfg\" instead","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/models/backbones/darknet.py","lineNumber":138,"sourceCode":"        cfg = dict(conv_cfg=conv_cfg, norm_cfg=norm_cfg, act_cfg=act_cfg)\n\n        self.conv1 = ConvModule(3, 32, 3, padding=1, **cfg)\n\n        self.cr_blocks = ['conv1']\n        for i, n_layers in enumerate(self.layers):\n            layer_name = f'conv_res_block{i + 1}'\n            in_c, out_c = self.channels[i]\n            self.add_module(\n                layer_name,\n                self.make_conv_res_block(in_c, out_c, n_layers, **cfg))\n            self.cr_blocks.append(layer_name)\n\n        self.norm_eval = norm_eval\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 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        outs = []\n        for i, layer_name in enumerate(self.cr_blocks):\n            cr_block = getattr(self, layer_name)","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/darknet.py#L120-L156","documentation":"Darknet backbone __init__ warns that the 'pretrained' string argument is deprecated in favor of 'init_cfg'. The model still builds — the checkpoint is converted into init_cfg=dict(type='Pretrained', checkpoint=...) — but the old API may be removed later.","triggerScenarios":"Instantiating Darknet(pretrained='open-mmlab://darknet53') or a config using pretrained=... in model backbone init args.","commonSituations":"Old MMDetection 2.x configs or tutorials passed backbone=dict(type='Darknet', pretrained='...'). New configs should use init_cfg.","solutions":["Replace pretrained='path_or_url' with init_cfg=dict(type='Pretrained', checkpoint='path_or_url') in the backbone config","Note both cannot be set simultaneously (assertion forbids init_cfg + pretrained together)","Update any saved config pipelines/scripts that generate model dicts"],"exampleFix":"# before\nmodel = dict(backbone=dict(type='Darknet', pretrained='open-mmlab://darknet53'))\n# after\nmodel = dict(backbone=dict(type='Darknet', init_cfg=dict(type='Pretrained', checkpoint='open-mmlab://darknet53')))","handlingStrategy":"validation","validationCode":"cfg = dict(type='Darknet')\nassert 'pretrained' not in cfg, 'use init_cfg instead of pretrained'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer init_cfg in all new configs","Lint configs for deprecated pretrained keys","Never combine pretrained with init_cfg (assertion error)"],"tags":["mmdet","darknet","deprecated-argument","init-cfg","backbone"],"backgroundTag":"deprecated-pretrained-argument","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}