{"record":{"id":"3ffe192a4497f0c4","repo":"roboflow/supervision","slug":"cannot-merge-compactmask-objects-with-different-im-3ffe19","errorCode":null,"errorMessage":"Cannot merge CompactMask objects with different image shapes.","messagePattern":"Cannot merge CompactMask objects with different image shapes\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/core.py","lineNumber":3346,"sourceCode":"                    all_xyxy[:, 0].min(),\n                    all_xyxy[:, 1].min(),\n                    all_xyxy[:, 2].max(),\n                    all_xyxy[:, 3].max(),\n                ]\n            ],\n            dtype=np.float32,\n        )\n        data = winner.data\n\n    # Mask union via logical OR. Preserve CompactMask outputs without re-cropping\n    # to the merged box, because source masks may legitimately extend outside it.\n    masks = [d.mask for d in detections if d.mask is not None]\n    if masks:\n        if all(isinstance(m, CompactMask) for m in masks):\n            compact_masks = cast(list[CompactMask], masks)\n            image_shape = compact_masks[0].image_shape\n            if any(m.image_shape != image_shape for m in compact_masks):\n                raise ValueError(\n                    \"Cannot merge CompactMask objects with different image shapes.\"\n                )\n            union_mask = np.zeros(image_shape, dtype=bool)\n            for compact_mask in compact_masks:\n                union_mask |= compact_mask.to_dense()[0]\n            union_xyxy = mask_to_xyxy(union_mask[np.newaxis]).astype(np.float32)\n            mask = CompactMask.from_dense(\n                masks=union_mask[np.newaxis],\n                xyxy=union_xyxy,\n                image_shape=image_shape,\n            )\n        else:\n            dense_masks = [\n                m.to_dense() if isinstance(m, CompactMask) else m for m in masks\n            ]\n            mask = np.logical_or.reduce(np.concatenate(dense_masks, axis=0))[np.newaxis]\n    else:\n        mask = None","sourceCodeStart":3328,"sourceCodeEnd":3364,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/core.py#L3328-L3364","documentation":"Error \"Cannot merge CompactMask objects with different image shapes.\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/detection/core.py:3346 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Merge only CompactMask objects created for the same image shape.","Normalize all masks to a single image_shape (resize/pad) before merging."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}