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 emitted by DetInferencer._load_weights_to_model when the loaded checkpoint's meta contains neither 'dataset_meta' nor legacy 'CLASSES', so COCO class names are assumed for labeling predictions.
Source
Thrown at mmdet/apis/det_inferencer.py:130
cfg (Config or ConfigDict, optional): The loaded config.
"""
if checkpoint is not None:
_load_checkpoint_to_model(model, checkpoint)
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).metainfoView on GitHub (pinned to cfd5d3a985)
Solutions
- Pass classes explicitly: DetInferencer(model, weights, classes=[...]) or set dataset_meta in the config
- Use a checkpoint saved by mmdet >= 3.0 training (it embeds dataset_meta)
- If the model really is COCO, ignore the warning
Example fix
// before inferencer = DetInferencer(model=cfg, weights='converted.pth') // after inferencer = DetInferencer(model=cfg, weights='converted.pth', classes=['a','b','c'])
Defensive patterns
Strategy: validation
Validate before calling
import torch
ckpt = torch.load('weights.pth', map_location='cpu')
meta = ckpt.get('meta', {})
if 'dataset_meta' not in meta and 'CLASSES' not in meta:
print('checkpoint lacks class names; pass classes explicitly') Prevention
- Inspect checkpoint meta before inferring
- Pass classes explicitly for converted weights
When it happens
Trigger: Running DetInferencer with a weights checkpoint whose meta dict lacks class info — typically checkpoints converted from other frameworks or from pre-3.x mmdet without meta fields.
Common situations: Using converted/foreign weights (e.g. torchvision or original-author released checkpoints) with DetInferencer; results still work but class labels may be wrong for non-COCO models.
Related errors
- Checkpoint is not loaded, and the inference result is calcul
- weights is None, use COCO classes by default.
- dataset_meta or class names are not saved in the checkpoint'
- palette does not exist, random is used by default. You can a
- Currently does not support saving datasample when return_dat
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/12214528b7569564.
Report an issue: GitHub.