open-mmlab/mmdetection · info
palette does not exist, random is used by default. You can a
Error message
palette does not exist, random is used by default. You can also set the palette to customize.
What it means
Warning from init_detector: after checking the palette argument, config dataset metainfo, and checkpoint meta, no palette exists, so 'random' is used for visualization colors.
Source
Thrown at mmdet/apis/inference.py:108
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(
'palette does not exist, random is used by default. '
'You can also set the palette to customize.')
model.dataset_meta['palette'] = 'random'
model.cfg = config # save the config in the model for convenience
model.to(device)
model.eval()
return model
ImagesType = Union[str, np.ndarray, Sequence[str], Sequence[np.ndarray]]
def inference_detector(
model: nn.Module,
imgs: ImagesType,
test_pipeline: Optional[Compose] = None,
text_prompt: Optional[str] = None,View on GitHub (pinned to cfd5d3a985)
Solutions
- Pass palette: init_detector(cfg, ckpt, palette='coco')
- Add 'palette' to dataset METAINFO in the config
- Ignore if color scheme doesn't matter
Example fix
// before model = init_detector(cfg, ckpt) # random palette // after model = init_detector(cfg, ckpt, palette='coco')
Defensive patterns
Strategy: fallback
Validate before calling
if palette == 'none' and 'palette' not in getattr(model, 'dataset_meta', {}):
model.dataset_meta['palette'] = 'coco' # deterministic choice Prevention
- Pass palette explicitly to init_detector for reproducible colors
When it happens
Trigger: init_detector(cfg, ckpt, palette='none') with a dataset/config/checkpoint that all lack a 'palette' entry.
Common situations: Custom datasets without palette in METAINFO; video inference via inference_detector then visualizer draws with random per-class colors.
Related errors
- palette does not exist, random is used by default. You can a
- Invalid type for palette: {type(palette)}
- checkpoint is None, use COCO classes by default.
- dataset_meta or class names are not saved in the checkpoint'
- The show is True, it means that only the prediction results
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/7b37667d453437db.
Report an issue: GitHub.