{"record":{"id":"e508cd35fc4453d8","repo":"roboflow/supervision","slug":"detections-mask-is-not-available","errorCode":null,"errorMessage":"Detections mask is not available","messagePattern":"Detections mask is not available","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/utils/object_size.py","lineNumber":310,"sourceCode":"\n        ```\n    \"\"\"\n    area_data = detections.data.get(AREA_DATA_FIELD)\n    if area_data is not None:\n        areas = np.asarray(area_data, dtype=np.float64)\n        if len(areas.shape) != 1 or len(areas) != len(detections):\n            raise ValueError(\n                \"Detection area metadata must be shaped (N,) and aligned \"\n                \"with detections\"\n            )\n        return get_area_size_category(areas)\n\n    if metric_target == MetricTarget.BOXES:\n        return get_bbox_size_category(detections.xyxy)\n    if metric_target == MetricTarget.MASKS:\n        mask = detections.mask\n        if mask is None:\n            raise ValueError(\"Detections mask is not available\")\n        return get_mask_size_category(mask)\n    if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:\n        oriented_box_coordinates = detections.data.get(ORIENTED_BOX_COORDINATES)\n        if oriented_box_coordinates is None:\n            raise ValueError(\"Detections oriented bounding boxes are not available\")\n        return get_obb_size_category(\n            cast(\n                npt.NDArray[np.number],\n                np.asarray(oriented_box_coordinates, dtype=np.float32),\n            )\n        )\n    raise ValueError(\"Invalid metric type\")\n","sourceCodeStart":292,"sourceCodeEnd":323,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/utils/object_size.py#L292-L323","documentation":"Raised by get_detection_size_category() when metric_target is MASKS but detections.mask is None. Size categorization for masks requires per-detection binary masks; if the Detections only carries boxes (e.g. from a detector without a segmentation head, or a connector that drops masks), the mask path cannot proceed. The code refuses rather than silently falling back to boxes.","triggerScenarios":"Calling get_detection_size_category(detections, MetricTarget.MASKS) on Detections constructed without a mask= argument, or after operations that drop the mask attribute.","commonSituations":"Running a mask-based metric on detector-only outputs (YOLO detection, not segmentation); Detections created from xyxy via from_* connectors that never populate mask; passing box predictions to a MASKS-target evaluation by mistake.","solutions":["Populate the mask: Detections(..., mask=np.stack(instance_masks))","Or use MetricTarget.BOXES when you only have axis-aligned boxes","Use a segmentation model/connector (e.g. SAM, YOLO-seg) whose output includes masks"],"exampleFix":"# before\ndets = sv.Detections(xyxy=boxes)\nget_detection_size_category(dets, MetricTarget.MASKS)  # mask is None\n\n# after\ndets = sv.Detections(xyxy=boxes, mask=masks)  # masks: (N, H, W) bool\nget_detection_size_category(dets, MetricTarget.MASKS)","handlingStrategy":"type-guard","validationCode":"from supervision.metrics.metric_target import MetricTarget\n\ntarget = MetricTarget.MASKS if detections.mask is not None else MetricTarget.BOXES\ncats = get_detection_size_category(detections, target)","typeGuard":"def has_masks(dets: sv.Detections) -> bool:\n    \"\"\"True when detections carry instance masks.\"\"\"\n    return dets.mask is not None","tryCatchPattern":"try:\n    cats = get_detection_size_category(detections, MetricTarget.MASKS)\nexcept ValueError as e:\n    if 'mask is not available' in str(e):\n        cats = get_detection_size_category(detections, MetricTarget.BOXES)\n    else:\n        raise","preventionTips":["Choose the metric target from what the model actually outputs (segmenter vs detector)","Set a pipeline invariant: MASKS-target runs require detections.mask is not None"],"tags":["metrics","object-size","mask","missing-data"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}