{"record":{"id":"16efb8807438b96a","repo":"roboflow/supervision","slug":"rle-size-must-be-height-width","errorCode":null,"errorMessage":"RLE size must be [height, width].","messagePattern":"RLE size must be \\[height, width\\]\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/compact_mask.py","lineNumber":821,"sourceCode":"            )\n\n        crop_rles: list[npt.NDArray[np.int32]] = []\n        crop_shapes_list: list[tuple[int, int]] = []\n        offsets_list: list[tuple[int, int]] = []\n\n        for mask_idx, rle in enumerate(rles):\n            if not isinstance(rle, Mapping):\n                raise ValueError(\"Each RLE payload must be a mapping.\")\n            if \"size\" not in rle or \"counts\" not in rle:\n                raise ValueError(\"Each RLE payload must contain 'size' and 'counts'.\")\n\n            try:\n                # COCO standard: size=[height, width] (h,w order per pycocotools spec)\n                rle_h, rle_w = rle[\"size\"]\n                rle_h = int(rle_h)\n                rle_w = int(rle_w)\n            except (TypeError, ValueError) as exc:\n                raise ValueError(\"RLE size must be [height, width].\") from exc\n\n            if (rle_h, rle_w) != (img_h, img_w):\n                raise ValueError(\n                    f\"RLE size {(rle_h, rle_w)} must match image_shape \"\n                    f\"{(img_h, img_w)}.\"\n                )\n\n            counts = _coco_rle_counts_to_array(rle[\"counts\"])\n            if int(np.sum(counts, dtype=np.int64)) != img_h * img_w:\n                raise ValueError(\n                    \"The sum of COCO RLE counts must match the image area.\"\n                )\n\n            x1, y1, x2, y2 = xyxy_arr[mask_idx]\n            x1i, y1i, x2i, y2i = int(x1), int(y1), int(x2), int(y2)\n            x1c = max(0, min(x1i, img_w - 1))\n            y1c = max(0, min(y1i, img_h - 1))\n","sourceCodeStart":803,"sourceCodeEnd":839,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/compact_mask.py#L803-L839","documentation":"Raised by CompactMask.from_coco_rle when rle['size'] cannot be unpacked into two integers — unpacking raised TypeError (wrong length or non-iterable) or ValueError (non-numeric values). The message restates the expected COCO convention: size must be a two-element [height, width] sequence.","triggerScenarios":"Passing size=[640] (one element), size=[h, w, c] (three elements), size='640x480' (a string), size=None, or size containing floats/strings like '720' that int() rejects in the tuple unpack.","commonSituations":"Building RLE dicts from custom metadata with wrong tuple arity; storing size as a string in a database and passing it raw; accidentally assigning 'size': counts and 'counts': size (swapped fields).","solutions":["Ensure size is exactly two integers in [height, width] order: [720, 1280].","If size arrives as a string, parse it first: tuple(map(int, s.split('x'))).","Check for swapped size/counts keys in the payload dict."],"exampleFix":"# before\nrles = [{\"size\": [4, 4, 3], \"counts\": [0, 2, 2, 2, 10]}]\n\n# after\nrles = [{\"size\": [4, 4], \"counts\": [0, 2, 2, 2, 10]}]","handlingStrategy":"type-guard","validationCode":"for r in rles:\n    size = r[\"size\"]\n    assert len(size) == 2, f\"size must have 2 elements, got {size!r}\"\n    h, w = int(size[0]), int(size[1])","typeGuard":"def is_valid_rle_size(size) -> bool:\n    return (\n        isinstance(size, (list, tuple))\n        and len(size) == 2\n        and all(isinstance(v, (int, float)) and not isinstance(v, bool) for v in size)\n    )","tryCatchPattern":null,"preventionTips":["Emit size as exactly [height, width] — two numbers, no channels dimension.","Parse string sizes ('720x480') into int pairs before building payloads.","Double-check size/counts are not swapped in dict construction."],"tags":["coco","rle","compact-mask","size-format","type-error"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}