{"record":{"id":"6c165a6d4c5c0e87","repo":"roboflow/supervision","slug":"invalid-metric-type","errorCode":null,"errorMessage":"Invalid metric type","messagePattern":"Invalid metric type","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/utils/object_size.py","lineNumber":87,"sourceCode":"        ...     [0, 0, 10, 10],    # 100 (Small)\n        ...     [0, 0, 50, 50],    # 2500 (Medium)\n        ...     [0, 0, 100, 100]   # 10000 (Large)\n        ... ])\n        >>> get_object_size_category(xyxy, MetricTarget.BOXES)\n        array([1, 2, 3])\n\n        ```\n    \"\"\"\n    if metric_target == MetricTarget.BOXES:\n        bbox_data = cast(npt.NDArray[np.number], data)\n        return get_bbox_size_category(bbox_data)\n    if metric_target == MetricTarget.MASKS:\n        mask_data = cast(npt.NDArray[np.bool_], data)\n        return get_mask_size_category(mask_data)\n    if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:\n        obb_data = cast(npt.NDArray[np.number], data)\n        return get_obb_size_category(obb_data)\n    raise ValueError(\"Invalid metric type\")\n\n\ndef get_bbox_size_category(xyxy: npt.NDArray[np.number]) -> npt.NDArray[np.int_]:\n    \"\"\"\n    Get the size category of a bounding boxes array.\n\n    Args:\n        xyxy: The bounding boxes array shaped (N, 4).\n\n    Returns:\n        The size category of each bounding box, matching\n        the enum values of ObjectSizeCategory. Shaped (N,).\n\n    Example:\n        ```pycon\n        >>> import numpy as np\n        >>> from supervision.metrics.utils.object_size import get_bbox_size_category\n        >>> xyxy = np.array([","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/utils/object_size.py#L69-L105","documentation":"Raised by get_size_category() in metrics/utils/object_size.py when the metric_target argument is not one of MetricTarget.BOXES, MASKS, or ORIENTED_BOUNDING_BOXES. The function dispatches on the enum to pick the right size-category computation (bbox area, mask pixel count, or OBB shoelace area). This is the final fall-through for an unknown enum value.","triggerScenarios":"Calling get_size_category(data, metric_target) with a value outside the handled MetricTarget members (e.g. a raw int/string, or a newly added enum member like class-agnostic variants).","commonSituations":"Passing metric_target loaded from a YAML/JSON config without converting to the enum; forward-compatibility mismatch when supervision adds a new MetricTarget that this helper does not yet support; passing None.","solutions":["Convert config values to the enum: MetricTarget(config_value) wrapped in try/except, or map strings explicitly","Check the enum members supported in your supervision version before calling"],"exampleFix":"# before\ncats = get_size_category(data, metric_target=\"masks\")  # str not handled\n\n# after\nfrom supervision.metrics.metric_target import MetricTarget\n\ncats = get_size_category(data, MetricTarget(\"masks\"))","handlingStrategy":"type-guard","validationCode":"from supervision.metrics.metric_target import MetricTarget\n\nif not isinstance(metric_target, MetricTarget):\n    metric_target = MetricTarget(metric_target)  # raises cleanly on bad values","typeGuard":"from supervision.metrics.metric_target import MetricTarget\n\ndef is_valid_metric_target(value: object) -> bool:\n    \"\"\"True when value is a MetricTarget enum member.\"\"\"\n    return isinstance(value, MetricTarget)","tryCatchPattern":"try:\n    cats = get_size_category(data, metric_target)\nexcept ValueError as e:\n    if 'Invalid metric type' in str(e):\n        cats = get_size_category(data, MetricTarget.BOXES)\n    else:\n        raise","preventionTips":["Normalize config strings to MetricTarget at the boundary: MetricTarget(str(cfg['target']).lower())","Log the resolved enum member once at startup to catch bad config early"],"tags":["metrics","object-size","enum","validation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}