open-mmlab/mmdetection · info

weights is None, use COCO classes by default.

Error message

weights is None, use COCO classes by default.

What it means

Companion warning to [244]: because weights is None, class names cannot come from a checkpoint, so COCO classes are used as the default labeling.

Source

Thrown at mmdet/apis/det_inferencer.py:138

                # 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:
                    warnings.warn(
                        'palette does not exist, random is used by default. '
                        'You can also set the palette to customize.')

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. Load real weights (fixes both warnings)
  2. Explicitly provide classes to DetInferencer
  3. Ignore if COCO labels are acceptable

Example fix

// before
inferencer = DetInferencer(cfg)
// after
inferencer = DetInferencer(cfg, weights='ckpt.pth', classes=my_classes)
Defensive patterns

Strategy: validation

Validate before calling

if weights is None:
    print('classes default to COCO; set classes= for correct labels')

Prevention

When it happens

Trigger: Same as 244 — DetInferencer built with weights=None; always emitted alongside the 'Checkpoint is not loaded' warning.

Common situations: Quick pipeline tests without weights; mislabeled outputs when the model is actually trained on a non-COCO dataset.

Related errors


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