{"record":{"id":"b50498b61eedb9c9","repo":"open-mmlab/mmdetection","slug":"invalid-type-for-palette-type-palette","errorCode":null,"errorMessage":"Invalid type for palette: {type(palette)}","messagePattern":"Invalid type for palette: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mmdet/visualization/palette.py","lineNumber":63,"sourceCode":"        np.random.seed(42)\n        palette = np.random.randint(0, 256, size=(num_classes, 3))\n        np.random.set_state(state)\n        dataset_palette = [tuple(c) for c in palette]\n    elif palette == 'coco':\n        from mmdet.datasets import CocoDataset, CocoPanopticDataset\n        dataset_palette = CocoDataset.METAINFO['palette']\n        if len(dataset_palette) < num_classes:\n            dataset_palette = CocoPanopticDataset.METAINFO['palette']\n    elif palette == 'citys':\n        from mmdet.datasets import CityscapesDataset\n        dataset_palette = CityscapesDataset.METAINFO['palette']\n    elif palette == 'voc':\n        from mmdet.datasets import VOCDataset\n        dataset_palette = VOCDataset.METAINFO['palette']\n    elif is_str(palette):\n        dataset_palette = [mmcv.color_val(palette)[::-1]] * num_classes\n    else:\n        raise TypeError(f'Invalid type for palette: {type(palette)}')\n\n    assert len(dataset_palette) >= num_classes, \\\n        'The length of palette should not be less than `num_classes`.'\n    return dataset_palette\n\n\ndef _get_adaptive_scales(areas: np.ndarray,\n                         min_area: int = 800,\n                         max_area: int = 30000) -> np.ndarray:\n    \"\"\"Get adaptive scales according to areas.\n\n    The scale range is [0.5, 1.0]. When the area is less than\n    ``min_area``, the scale is 0.5 while the area is larger than\n    ``max_area``, the scale is 1.0.\n\n    Args:\n        areas (ndarray): The areas of bboxes or masks with the\n            shape of (n, ).","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/visualization/palette.py#L45-L81","documentation":"get_palette raises TypeError when the palette argument is neither a known dataset palette name ('coco','voc','random',...), nor any other string (treated as an mmcv color val), nor a sequence of colors.","triggerScenarios":"Calling mmdet.visualization.palette.get_palette(palette, num_classes) with e.g. an int, dict, or None as palette; reached from visualizer drawing (_draw_instances/_draw_panoptic_seg) when dataset_meta['palette'] holds an invalid value.","commonSituations":"Setting palette in a config or DetInferencer(palette=...) to a non-string/non-list value; custom datasets whose METAINFO palette entry is malformed.","solutions":["Pass a recognized palette name string (e.g. 'coco', 'voc', 'random') or a list of RGB tuples","Fix the dataset METAINFO['palette'] / inferencer palette argument to a valid type","Check for typos if you intended a named palette — unknown strings fall through to mmcv.color_val which may also fail"],"exampleFix":"// before\nget_palette(3, 80)  # TypeError\n// after\nget_palette('random', 80)","handlingStrategy":"type-guard","validationCode":"from mmengine.utils import is_str\nimport numpy as np\ndef valid_palette(p):\n    return is_str(p) or (isinstance(p, (list, tuple)) and len(p) > 0)\nassert valid_palette(palette)","typeGuard":"def is_valid_palette(p) -> bool:\n    from mmengine.utils import is_str\n    return is_str(p) or isinstance(p, (list, tuple))","tryCatchPattern":"try:\n    get_palette(palette, n)\nexcept TypeError as e:\n    if 'Invalid type for palette' in str(e):\n        palette = 'random'\n        get_palette(palette, n)","preventionTips":["Validate config-supplied palette types before building visualizers","Prefer documented palette names"],"tags":["python","validation","palette","typeerror","visualization"],"backgroundTag":"invalid-argument-type","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}