{"record":{"id":"c9910d09e09fd687","repo":"open-mmlab/mmdetection","slug":"palette-does-not-exist-random-is-used-by-default","errorCode":null,"errorMessage":"palette does not exist, random is used by default. You can also set the palette to customize.","messagePattern":"palette does not exist, random is used by default\\. You can also set the palette to customize\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"mmdet/apis/det_inferencer.py","lineNumber":154,"sourceCode":"                          'result is calculated by the randomly initialized '\n                          'model!')\n            warnings.warn('weights is None, use COCO classes by default.')\n            model.dataset_meta = {'classes': get_classes('coco')}\n\n        # Priority:  args.palette -> config -> checkpoint\n        if self.palette != 'none':\n            model.dataset_meta['palette'] = self.palette\n        else:\n            test_dataset_cfg = copy.deepcopy(cfg.test_dataloader.dataset)\n            # lazy init. We only need the metainfo.\n            test_dataset_cfg['lazy_init'] = True\n            metainfo = DATASETS.build(test_dataset_cfg).metainfo\n            cfg_palette = metainfo.get('palette', None)\n            if cfg_palette is not None:\n                model.dataset_meta['palette'] = cfg_palette\n            else:\n                if 'palette' not in model.dataset_meta:\n                    warnings.warn(\n                        'palette does not exist, random is used by default. '\n                        'You can also set the palette to customize.')\n                    model.dataset_meta['palette'] = 'random'\n\n    def _init_pipeline(self, cfg: ConfigType) -> Compose:\n        \"\"\"Initialize the test pipeline.\"\"\"\n        pipeline_cfg = cfg.test_dataloader.dataset.pipeline\n\n        # For inference, the key of ``img_id`` is not used.\n        if 'meta_keys' in pipeline_cfg[-1]:\n            pipeline_cfg[-1]['meta_keys'] = tuple(\n                meta_key for meta_key in pipeline_cfg[-1]['meta_keys']\n                if meta_key != 'img_id')\n\n        load_img_idx = self._get_transform_idx(\n            pipeline_cfg, ('LoadImageFromFile', LoadImageFromFile))\n        if load_img_idx == -1:\n            raise ValueError(","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/apis/det_inferencer.py#L136-L172","documentation":"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.","triggerScenarios":"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).","commonSituations":"Custom datasets whose METAINFO omits 'palette'; converted checkpoints; results are correct but instance colors vary run to run.","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"],"exampleFix":"// before\ninferencer = DetInferencer(cfg, weights=w)  # random palette\n// after\ninferencer = DetInferencer(cfg, weights=w, palette='coco')","handlingStrategy":"fallback","validationCode":"palette = palette if palette != 'none' else 'random'  # pre-decide instead of relying on silent default","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set palette explicitly in configs for deterministic visuals","Add palette to custom dataset METAINFO"],"tags":["python","warning","palette","inferencer","visualization"],"backgroundTag":"missing-visualization-palette","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}