{"record":{"id":"60f90fd92944e76e","repo":"open-mmlab/mmdetection","slug":"checkpoint-is-not-loaded-and-the-inference-result","errorCode":null,"errorMessage":"Checkpoint is not loaded, and the inference result is calculated by the randomly initialized model!","messagePattern":"Checkpoint is not loaded, and the inference result is calculated by the randomly initialized model!","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mmdet/apis/det_inferencer.py","lineNumber":135,"sourceCode":"            checkpoint_meta = checkpoint.get('meta', {})\n            # save the dataset_meta in the model for convenience\n            if 'dataset_meta' in checkpoint_meta:\n                # mmdet 3.x, all keys should be lowercase\n                model.dataset_meta = {\n                    k.lower(): v\n                    for k, v in checkpoint_meta['dataset_meta'].items()\n                }\n            elif 'CLASSES' in checkpoint_meta:\n                # < mmdet 3.x\n                classes = checkpoint_meta['CLASSES']\n                model.dataset_meta = {'classes': classes}\n            else:\n                warnings.warn(\n                    'dataset_meta or class names are not saved in the '\n                    'checkpoint\\'s meta data, use COCO classes by default.')\n                model.dataset_meta = {'classes': get_classes('coco')}\n        else:\n            warnings.warn('Checkpoint is not loaded, and the inference '\n                          'result is calculated by the randomly initialized '\n                          'model!')\n            warnings.warn('weights is None, use COCO classes by default.')\n            model.dataset_meta = {'classes': get_classes('coco')}\n\n        # Priority:  args.palette -> config -> checkpoint\n        if self.palette != 'none':\n            model.dataset_meta['palette'] = self.palette\n        else:\n            test_dataset_cfg = copy.deepcopy(cfg.test_dataloader.dataset)\n            # lazy init. We only need the metainfo.\n            test_dataset_cfg['lazy_init'] = True\n            metainfo = DATASETS.build(test_dataset_cfg).metainfo\n            cfg_palette = metainfo.get('palette', None)\n            if cfg_palette is not None:\n                model.dataset_meta['palette'] = cfg_palette\n            else:\n                if 'palette' not in model.dataset_meta:","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/apis/det_inferencer.py#L117-L153","documentation":"Warning from DetInferencer._load_weights_to_model when weights is None (or not loadable), so inference runs on a randomly initialized model — predictions will be meaningless.","triggerScenarios":"Constructing DetInferencer without a weights argument, or with weights=None, while still calling it on images.","commonSituations":"Intending to demo the pipeline, forgetting to pass the checkpoint path, or passing a config where pretrained weights were expected; also when building from a config whose init checkpoint path is wrong.","solutions":["Pass trained weights: DetInferencer(cfg, weights='checkpoint.pth') or inferencer = DetInferencer('model-name') from the model zoo","Verify the checkpoint path exists","If random init was intentional (debugging), ignore the warning"],"exampleFix":"// before\ninferencer = DetInferencer(model='configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py')\n// after\ninferencer = DetInferencer(model='configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py', weights='faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth')","handlingStrategy":"validation","validationCode":"import os\nassert weights is None or os.path.isfile(weights) or weights.startswith('http'), f'bad weights: {weights}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a verified checkpoint path for real inference","Treat this warning as a red flag in result pipelines"],"tags":["python","warning","checkpoint","random-init","inferencer"],"backgroundTag":"model-weights-not-loaded","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}