{"record":{"id":"138f495936ff8268","repo":"open-mmlab/mmdetection","slug":"deprecationwarning-pretrained-is-deprecated-plea-138f49","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":"info","filePath":"mmdet/models/backbones/swin.py","lineNumber":564,"sourceCode":"                 pretrained=None,\n                 convert_weights=False,\n                 frozen_stages=-1,\n                 init_cfg=None):\n        self.convert_weights = convert_weights\n        self.frozen_stages = frozen_stages\n        if isinstance(pretrain_img_size, int):\n            pretrain_img_size = to_2tuple(pretrain_img_size)\n        elif isinstance(pretrain_img_size, tuple):\n            if len(pretrain_img_size) == 1:\n                pretrain_img_size = to_2tuple(pretrain_img_size[0])\n            assert len(pretrain_img_size) == 2, \\\n                f'The size of image should have length 1 or 2, ' \\\n                f'but got {len(pretrain_img_size)}'\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            self.init_cfg = init_cfg\n        else:\n            raise TypeError('pretrained must be a str or None')\n\n        super(SwinTransformer, self).__init__(init_cfg=init_cfg)\n\n        num_layers = len(depths)\n        self.out_indices = out_indices\n        self.use_abs_pos_embed = use_abs_pos_embed\n\n        assert strides[0] == patch_size, 'Use non-overlapping patch embed.'\n\n        self.patch_embed = PatchEmbed(\n            in_channels=in_channels,\n            embed_dims=embed_dims,","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/swin.py#L546-L582","documentation":"Swin Transformer backbone constructor warns that the legacy `pretrained` string argument is deprecated in favor of the standardized `init_cfg` mechanism. The constructor asserts the two cannot be combined and converts `pretrained` into `init_cfg=dict(type='Pretrained', checkpoint=pretrained)` after warning. It is purely informational; behavior is preserved.","triggerScenarios":"Calling SwinTransformer(..., pretrained='path-or-url') or passing pretrained in a config file instead of init_cfg.","commonSituations":"Old MMDetection/MMPretrain configs (pre-v2.x style) reused with newer mmdet; tutorials demonstrating `model = build_detector(cfg); model.backbone.pretrained = ...`.","solutions":["Replace `pretrained='...'` with `init_cfg=dict(type='Pretrained', checkpoint='...')` in the backbone config","Never set both init_cfg and pretrained — the constructor asserts they are mutually exclusive"],"exampleFix":"// before\nbackbone=dict(type='SwinTransformer', pretrained='swin_tiny.pth', ...)\n// after\nbackbone=dict(type='SwinTransformer', init_cfg=dict(type='Pretrained', checkpoint='swin_tiny.pth'), ...)","handlingStrategy":"validation","validationCode":"cfg = dict(type='SwinTransformer', ...)\nassert not ('pretrained' in cfg and 'init_cfg' in cfg)\ncfg.setdefault('init_cfg', dict(type='Pretrained', checkpoint=cfg.pop('pretrained', None))) if cfg.get('pretrained') else None","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use init_cfg exclusively in all new configs","Never combine init_cfg and pretrained — the constructor asserts against it"],"tags":["mmdet","swin-transformer","deprecation","pretrained-weights"],"backgroundTag":"deprecated-argument-migration","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}