open-mmlab/mmdetection · warning
dataset_meta or class names are not saved in the checkpoint'
Error message
dataset_meta or class names are not saved in the checkpoint's meta data, use COCO classes by default.
What it means
Warning from init_detector: the checkpoint loaded successfully but its meta dict has neither 'dataset_meta' nor legacy 'CLASSES', so COCO classes are the default labels.
Source
Thrown at mmdet/apis/inference.py:90
else:
checkpoint = load_checkpoint(model, checkpoint, map_location='cpu')
# Weights converted from elsewhere may not have meta fields.
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.simplefilter('once')
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')}
# Priority: args.palette -> config -> checkpoint
if palette != 'none':
model.dataset_meta['palette'] = palette
else:
test_dataset_cfg = copy.deepcopy(config.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(View on GitHub (pinned to cfd5d3a985)
Solutions
- Prefer checkpoints from official mmdet training
- Set classes via config: model.test_cfg / dataset metainfo, or manually assign model.dataset_meta after init
- Patch the checkpoint meta: ckpt['meta']['dataset_meta'] = {'classes': [...]} then re-save
Example fix
// before
model = init_detector(cfg, 'converted.pth')
// after
model = init_detector(cfg, 'converted.pth')
model.dataset_meta = {'classes': my_class_list} Defensive patterns
Strategy: validation
Validate before calling
import torch
meta = torch.load(ckpt, map_location='cpu').get('meta', {})
assert 'dataset_meta' in meta or 'CLASSES' in meta or explicit_classes, 'labels will default to COCO' Prevention
- Check checkpoint meta before relying on predicted labels
- Set model.dataset_meta manually for converted weights
When it happens
Trigger: init_detector(cfg, 'weights.pth') where weights.pth was converted from another framework or stripped of meta.
Common situations: Using mmengine-converted or third-party weights; predictions are fine but class names/ids may mismatch for non-COCO-trained models.
Related errors
- dataset_meta or class names are not saved in the checkpoint'
- checkpoint is None, use COCO classes by default.
- Checkpoint is not loaded, and the inference result is calcul
- weights is None, use COCO classes by default.
- palette does not exist, random is used by default. You can a
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/e99cf761adeafeb2.
Report an issue: GitHub.