{"record":{"id":"51716008db42a1da","repo":"open-mmlab/mmdetection","slug":"metric-should-be-one-of-bbox-segm-proposal","errorCode":null,"errorMessage":"metric should be one of 'bbox', 'segm', 'proposal', 'proposal_fast', but got {metric}.","messagePattern":"metric should be one of 'bbox', 'segm', 'proposal', 'proposal_fast', but got (.+?)\\.","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"mmdet/evaluation/metrics/coco_metric.py","lineNumber":91,"sourceCode":"                 classwise: bool = False,\n                 proposal_nums: Sequence[int] = (100, 300, 1000),\n                 iou_thrs: Optional[Union[float, Sequence[float]]] = None,\n                 metric_items: Optional[Sequence[str]] = None,\n                 format_only: bool = False,\n                 outfile_prefix: Optional[str] = None,\n                 file_client_args: dict = None,\n                 backend_args: dict = None,\n                 collect_device: str = 'cpu',\n                 prefix: Optional[str] = None,\n                 sort_categories: bool = False,\n                 use_mp_eval: bool = False) -> None:\n        super().__init__(collect_device=collect_device, prefix=prefix)\n        # coco evaluation metrics\n        self.metrics = metric if isinstance(metric, list) else [metric]\n        allowed_metrics = ['bbox', 'segm', 'proposal', 'proposal_fast']\n        for metric in self.metrics:\n            if metric not in allowed_metrics:\n                raise KeyError(\n                    \"metric should be one of 'bbox', 'segm', 'proposal', \"\n                    f\"'proposal_fast', but got {metric}.\")\n\n        # do class wise evaluation, default False\n        self.classwise = classwise\n        # whether to use multi processing evaluation, default False\n        self.use_mp_eval = use_mp_eval\n\n        # proposal_nums used to compute recall or precision.\n        self.proposal_nums = list(proposal_nums)\n\n        # iou_thrs used to compute recall or precision.\n        if iou_thrs is None:\n            iou_thrs = np.linspace(\n                .5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)\n        self.iou_thrs = iou_thrs\n        self.metric_items = metric_items\n        self.format_only = format_only","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/evaluation/metrics/coco_metric.py#L73-L109","documentation":"CocoMetric.__init__ validates the `metric` argument against the allowed COCO evaluation types: 'bbox', 'segm', 'proposal', 'proposal_fast'. Any other string (or a list containing one) raises this KeyError because mmdetection has no COCO eval implementation for it. This guards against typos and unsupported eval types at construction time, before any training/eval loop starts.","triggerScenarios":"Instantiating CocoMetric(metric='box') / 'bbox-segm' / 'AP' / ['bbox','wrong'], or passing a val_cfg/val_evaluator config in mmdet where the metric name is misspelled or belongs to another dataset's metric class (e.g. CrowdHuman 'MR'/'JI').","commonSituations":"Copy-pasting an evaluator config from a different task (e.g. a CrowdHuman or LVIS config) into a COCO config; using 'AP' or 'mAP' as a metric name; upgrading configs where older metric aliases existed.","solutions":["Set metric to one of 'bbox', 'segm', 'proposal', 'proposal_fast' (or a list of them), e.g. dict(type='CocoMetric', metric=['bbox','segm'])","If you need a different dataset's metrics, use the matching metric class (e.g. CrowdHumanMetric, LVISMetric)","If you only want quick proposal quality, use 'proposal_fast'"],"exampleFix":"// before\nval_evaluator = dict(type='CocoMetric', metric='AP')\n// after\nval_evaluator = dict(type='CocoMetric', metric='bbox')","handlingStrategy":"validation","validationCode":"ALLOWED = {'bbox','segm','proposal','proposal_fast'}\nmetrics = cfg['val_evaluator']['metric']\nmetrics = [metrics] if isinstance(metrics, str) else metrics\nbad = [m for m in metrics if m not in ALLOWED]\nassert not bad, f'Invalid CocoMetric metric(s): {bad}, allowed: {sorted(ALLOWED)}'","typeGuard":"from typing import Union, List\n\ndef is_valid_coco_metric(m: Union[str, List[str]]) -> bool:\n    allowed = {'bbox', 'segm', 'proposal', 'proposal_fast'}\n    items = [m] if isinstance(m, str) else m\n    return bool(items) and all(x in allowed for x in items)","tryCatchPattern":null,"preventionTips":["Validate metric names against the class's allowed_metrics before building the evaluator","Use a config linter or unit test that instantiates val_evaluator for every config in the repo","Copy metric names from the official mmdet config of the same task, not from other datasets"],"tags":["mmdetection","coco","metric-validation","config-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}