open-mmlab/mmdetection · warning

Checkpoint is not loaded, and the inference result is calcul

Error message

Checkpoint is not loaded, and the inference result is calculated by the randomly initialized model!

What it means

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.

Source

Thrown at mmdet/apis/det_inferencer.py:135

            checkpoint_meta = checkpoint.get('meta', {})
            # save the dataset_meta in the model for convenience
            if 'dataset_meta' in checkpoint_meta:
                # mmdet 3.x, all keys should be lowercase
                model.dataset_meta = {
                    k.lower(): v
                    for k, v in checkpoint_meta['dataset_meta'].items()
                }
            elif 'CLASSES' in checkpoint_meta:
                # < mmdet 3.x
                classes = checkpoint_meta['CLASSES']
                model.dataset_meta = {'classes': classes}
            else:
                warnings.warn(
                    'dataset_meta or class names are not saved in the '
                    'checkpoint\'s meta data, use COCO classes by default.')
                model.dataset_meta = {'classes': get_classes('coco')}
        else:
            warnings.warn('Checkpoint is not loaded, and the inference '
                          'result is calculated by the randomly initialized '
                          'model!')
            warnings.warn('weights is None, use COCO classes by default.')
            model.dataset_meta = {'classes': get_classes('coco')}

        # Priority:  args.palette -> config -> checkpoint
        if self.palette != 'none':
            model.dataset_meta['palette'] = self.palette
        else:
            test_dataset_cfg = copy.deepcopy(cfg.test_dataloader.dataset)
            # lazy init. We only need the metainfo.
            test_dataset_cfg['lazy_init'] = True
            metainfo = DATASETS.build(test_dataset_cfg).metainfo
            cfg_palette = metainfo.get('palette', None)
            if cfg_palette is not None:
                model.dataset_meta['palette'] = cfg_palette
            else:
                if 'palette' not in model.dataset_meta:

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Pass trained weights: DetInferencer(cfg, weights='checkpoint.pth') or inferencer = DetInferencer('model-name') from the model zoo
  2. Verify the checkpoint path exists
  3. If random init was intentional (debugging), ignore the warning

Example fix

// before
inferencer = DetInferencer(model='configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py')
// after
inferencer = DetInferencer(model='configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py', weights='faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth')
Defensive patterns

Strategy: validation

Validate before calling

import os
assert weights is None or os.path.isfile(weights) or weights.startswith('http'), f'bad weights: {weights}'

Prevention

When it happens

Trigger: Constructing DetInferencer without a weights argument, or with weights=None, while still calling it on images.

Common situations: 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.

Related errors


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/60f90fd92944e76e. Report an issue: GitHub.