open-mmlab/mmdetection · info
palette does not exist, random is used by default. You can…
Error message
palette does not exist, random is used by default. You can also set the palette to customize.
What it means
Warning from _load_weights_to_model: after checking args.palette, config dataset metainfo, and checkpoint, no palette was found anywhere, so 'random' palette is assigned for visualization colors.
Solutions
- Pass palette explicitly: DetInferencer(..., palette='coco')
- Add 'palette' to your dataset's METAINFO in the config
- Accept random colors if appearance doesn't matter
Example fix
// before inferencer = DetInferencer(cfg, weights=w) # random palette // after inferencer = DetInferencer(cfg, weights=w, palette='coco')
Defensive patterns
Strategy: fallback
Validate before calling
palette = palette if palette != 'none' else 'random' # pre-decide instead of relying on silent default
Prevention
- Set palette explicitly in configs for deterministic visuals
- Add palette to custom dataset METAINFO
When it happens
Trigger: Running DetInferencer where palette='none' (default), the test dataset metainfo has no 'palette' key, and the checkpoint/config dataset_meta also lacks palette (e.g. non-COCO dataset without palette in METAINFO).
Common situations: Custom datasets whose METAINFO omits 'palette'; converted checkpoints; results are correct but instance colors vary run to run.
Related errors
- palette does not exist, random is used by default. You can…
- Checkpoint is not loaded, and the inference result is…
- Currently does not support saving datasample when…
- dataset_meta or class names are not saved in the…
- Invalid type for palette
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/c9910d09e09fd687.
Report an issue: GitHub.
Appendix: source
Thrown at mmdet/apis/det_inferencer.py:154
'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.')
model.dataset_meta['palette'] = 'random'
def _init_pipeline(self, cfg: ConfigType) -> Compose:
"""Initialize the test pipeline."""
pipeline_cfg = cfg.test_dataloader.dataset.pipeline
# For inference, the key of ``img_id`` is not used.
if 'meta_keys' in pipeline_cfg[-1]:
pipeline_cfg[-1]['meta_keys'] = tuple(
meta_key for meta_key in pipeline_cfg[-1]['meta_keys']
if meta_key != 'img_id')
load_img_idx = self._get_transform_idx(
pipeline_cfg, ('LoadImageFromFile', LoadImageFromFile))
if load_img_idx == -1:
raise ValueError(View on GitHub (pinned to cfd5d3a985)