{"record":{"id":"7b37667d453437db","repo":"open-mmlab/mmdetection","slug":"palette-does-not-exist-random-is-used-by-default-7b3766","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/inference.py","lineNumber":108,"sourceCode":"            warnings.warn(\n                'dataset_meta or class names are not saved in the '\n                'checkpoint\\'s meta data, use COCO classes by default.')\n            model.dataset_meta = {'classes': get_classes('coco')}\n\n    # Priority:  args.palette -> config -> checkpoint\n    if palette != 'none':\n        model.dataset_meta['palette'] = palette\n    else:\n        test_dataset_cfg = copy.deepcopy(config.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    model.cfg = config  # save the config in the model for convenience\n    model.to(device)\n    model.eval()\n    return model\n\n\nImagesType = Union[str, np.ndarray, Sequence[str], Sequence[np.ndarray]]\n\n\ndef inference_detector(\n    model: nn.Module,\n    imgs: ImagesType,\n    test_pipeline: Optional[Compose] = None,\n    text_prompt: Optional[str] = None,","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/apis/inference.py#L90-L126","documentation":"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.","triggerScenarios":"init_detector(cfg, ckpt, palette='none') with a dataset/config/checkpoint that all lack a 'palette' entry.","commonSituations":"Custom datasets without palette in METAINFO; video inference via inference_detector then visualizer draws with random per-class colors.","solutions":["Pass palette: init_detector(cfg, ckpt, palette='coco')","Add 'palette' to dataset METAINFO in the config","Ignore if color scheme doesn't matter"],"exampleFix":"// before\nmodel = init_detector(cfg, ckpt)  # random palette\n// after\nmodel = init_detector(cfg, ckpt, palette='coco')","handlingStrategy":"fallback","validationCode":"if palette == 'none' and 'palette' not in getattr(model, 'dataset_meta', {}):\n    model.dataset_meta['palette'] = 'coco'  # deterministic choice","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass palette explicitly to init_detector for reproducible colors"],"tags":["python","warning","palette","init-detector","visualization"],"backgroundTag":"missing-visualization-palette","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}