{"record":{"id":"27b45c57643f00de","repo":"open-mmlab/mmdetection","slug":"no-pre-trained-weights-for-self-class-name-27b45c","errorCode":null,"errorMessage":"No pre-trained weights for {self.__class__.__name__}, training start from scratch","messagePattern":"No pre-trained weights for (.+?), training start from scratch","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/models/backbones/swin.py","lineNumber":674,"sourceCode":"            self.drop_after_pos.eval()\n\n        for i in range(1, self.frozen_stages + 1):\n\n            if (i - 1) in self.out_indices:\n                norm_layer = getattr(self, f'norm{i-1}')\n                norm_layer.eval()\n                for param in norm_layer.parameters():\n                    param.requires_grad = False\n\n            m = self.stages[i - 1]\n            m.eval()\n            for param in m.parameters():\n                param.requires_grad = False\n\n    def init_weights(self):\n        logger = MMLogger.get_current_instance()\n        if self.init_cfg is None:\n            logger.warn(f'No pre-trained weights for '\n                        f'{self.__class__.__name__}, '\n                        f'training start from scratch')\n            if self.use_abs_pos_embed:\n                trunc_normal_(self.absolute_pos_embed, std=0.02)\n            for m in self.modules():\n                if isinstance(m, nn.Linear):\n                    trunc_normal_init(m, std=.02, bias=0.)\n                elif isinstance(m, nn.LayerNorm):\n                    constant_init(m, 1.0)\n        else:\n            assert 'checkpoint' in self.init_cfg, f'Only support ' \\\n                                                  f'specify `Pretrained` in ' \\\n                                                  f'`init_cfg` in ' \\\n                                                  f'{self.__class__.__name__} '\n            ckpt = CheckpointLoader.load_checkpoint(\n                self.init_cfg.checkpoint, logger=logger, map_location='cpu')\n            if 'state_dict' in ckpt:\n                _state_dict = ckpt['state_dict']","sourceCodeStart":656,"sourceCodeEnd":692,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/backbones/swin.py#L656-L692","documentation":"Swin's init_weights logs (via logger.warn) that no checkpoint was configured, so weights are randomly initialized and training starts from scratch. This happens when init_cfg is None. It is expected for training-from-scratch runs but a red flag when you intended to load a pretrained model.","triggerScenarios":"Building a SwinTransformer backbone without init_cfg/pretrained and calling .init_weights() (directly or via detector init).","commonSituations":"Checkpoint path typo or missing init_cfg in config; user assumed default weights load automatically; fine-tuning config copied but init_cfg removed.","solutions":["Verify you intended to train from scratch; if not, add init_cfg=dict(type='Pretrained', checkpoint='<path-or-url>') to the backbone config","Check that the checkpoint path/URL exists and is readable","If from-scratch is intended, ignore the message"],"exampleFix":"// before\nbackbone=dict(type='SwinTransformer', embed_dims=96, ...)\n// after\nbackbone=dict(type='SwinTransformer', embed_dims=96, init_cfg=dict(type='Pretrained', checkpoint='https://download.openmmlab.com/...'), ...)","handlingStrategy":"validation","validationCode":"backbone_cfg = cfg['model']['backbone']\nif backbone_cfg.get('init_cfg') is None:\n    logging.warning('Swin will train from scratch; add init_cfg if a checkpoint was intended')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always verify backbone.init_cfg before training when fine-tuning is intended","Log the effective init_cfg at startup"],"tags":["mmdet","swin-transformer","pretrained-weights","initialization"],"backgroundTag":"missing-pretrained-weights","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}