{"record":{"id":"eeccc37be752f9bd","repo":"roboflow/supervision","slug":"is-crowd-length-len-is-crowd-must-match-bo","errorCode":null,"errorMessage":"`is_crowd` length ({len(is_crowd)}) must match `boxes_true` length ({len(boxes_true)}).","messagePattern":"`is_crowd` length \\((.+?)\\) must match `boxes_true` length \\((.+?)\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/utils/iou_and_nms.py","lineNumber":356,"sourceCode":"        ... ]\n        >>> boxes_detection = [\n        ...     [12, 22, 28, 38],\n        ...     [16, 26, 36, 46]\n        ... ]\n        >>> is_crowd = [False, False]\n        >>> ious = sv.box_iou_batch_with_jaccard(\n        ...     boxes_true=boxes_true,\n        ...     boxes_detection=boxes_detection,\n        ...     is_crowd=is_crowd\n        ... )\n        >>> ious  # doctest: +ELLIPSIS\n        array([[0.886..., 0.496...],\n               [0.4  ..., 0.862...]])\n\n        ```\n    \"\"\"\n    if len(is_crowd) != len(boxes_true):\n        raise ValueError(\n            f\"`is_crowd` length ({len(is_crowd)}) must match \"\n            f\"`boxes_true` length ({len(boxes_true)}).\"\n        )\n    if len(boxes_detection) == 0 or len(boxes_true) == 0:\n        return np.empty((len(boxes_detection), len(boxes_true)), dtype=np.float64)\n\n    # Smallest number to avoid division by zero.\n    eps = np.spacing(1)\n    gt = np.asarray(boxes_true, dtype=np.float64)\n    dt = np.asarray(boxes_detection, dtype=np.float64)\n    crowd = np.asarray(is_crowd, dtype=bool)\n\n    # Boxes are [x, y, w, h]. Build the far corners as `x2 = x + w` (rather than\n    # reusing `w`) so that the area/intersection arithmetic is bit-identical to\n    # the per-pair reference it replaces.\n    gt_x2, gt_y2 = gt[:, 0] + gt[:, 2], gt[:, 1] + gt[:, 3]\n    dt_x2, dt_y2 = dt[:, 0] + dt[:, 2], dt[:, 1] + dt[:, 3]\n","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/utils/iou_and_nms.py#L338-L374","documentation":"Raised by sv.box_iou_batch_with_jaccard when the is_crowd flag array length does not equal the number of ground-truth boxes. is_crowd switches each ground-truth box between IoU and Jaccard-style overlap; supervision requires a one-to-one flag per ground-truth box, so a length mismatch is a caller error.","triggerScenarios":"sv.box_iou_batch_with_jaccard(boxes_true=gt, boxes_detection=dt, is_crowd=flags) with len(flags) != len(gt), e.g. flags computed from the detection array or a hard-coded np.zeros(5) reused after the GT set changed size.","commonSituations":"Reusing COCO-style is_crowd arrays after filtering ground truths (e.g. dropping ignore-region boxes) without filtering the flags in lockstep; building flags from the wrong list during evaluation-harness refactors; mAP/evaluation code where gt and flags come from different loaders.","solutions":["Derive flags from the same filtering pass as boxes_true: is_crowd = np.array([a.get('iscrowd', 0) for a in gt_annos])","Filter both together: mask = ...; boxes_true = boxes_true[mask]; is_crowd = is_crowd[mask]","Default correctly when unsure: np.zeros(len(boxes_true), dtype=bool)"],"exampleFix":"# before\nkeep = areas >= min_area\nious = sv.box_iou_batch_with_jaccard(boxes_true[keep], boxes_detection, is_crowd=flags)  # flags unfiltered\n# after\nkeep = areas >= min_area\nious = sv.box_iou_batch_with_jaccard(boxes_true[keep], boxes_detection, is_crowd=flags[keep])","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef aligned_crowd_flags(boxes_true, is_crowd):\n    flags = np.asarray(is_crowd, dtype=bool).reshape(-1)\n    assert len(flags) == len(boxes_true), f\"is_crowd {len(flags)} != boxes_true {len(boxes_true)}\"\n    return flags","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build is_crowd from the same annotation list you build boxes_true from","Apply identical boolean filters to boxes and flags in evaluation code","Default to np.zeros(len(boxes_true), dtype=bool) when crowd info is absent"],"tags":["iou","evaluation","shape-mismatch","validation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}