{"record":{"id":"84629c1bacb82019","repo":"roboflow/supervision","slug":"cannot-merge-compactmask-objects-with-different-im-84629c","errorCode":null,"errorMessage":"Cannot merge CompactMask objects with different image shapes: {sorted(compact_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":2458,"sourceCode":"            masks = [d.mask for d in detections_list]\n            if all(m is None for m in masks):\n                return None\n            if any(m is None for m in masks):\n                raise ValueError(\"All or none of the 'mask' fields must be None\")\n            if all(isinstance(m, CompactMask) for m in masks):\n                return CompactMask.merge(cast(list[CompactMask], masks))\n            if all(not isinstance(m, CompactMask) for m in masks):\n                # All-dense: preserve backward-compatible dense stacking.\n                return cast(\n                    npt.NDArray[np.generic], np.vstack([np.asarray(m) for m in masks])\n                )\n            # Mixed dense and CompactMask: convert dense masks to CompactMask to\n            # avoid materialising a full (N, H, W) stack.\n            compact_image_shapes = {\n                m.image_shape for m in masks if isinstance(m, CompactMask)\n            }\n            if len(compact_image_shapes) != 1:\n                raise ValueError(\n                    \"Cannot merge CompactMask objects with different image shapes: \"\n                    f\"{sorted(compact_image_shapes)}\"\n                )\n            image_shape: tuple[int, int] = next(iter(compact_image_shapes))\n            compact_list: list[CompactMask] = []\n            for d, m in zip(detections_list, masks):\n                if isinstance(m, CompactMask):\n                    compact_list.append(m)\n                else:\n                    dense = np.asarray(m, dtype=bool)\n                    if dense.shape[1:] != image_shape:\n                        raise ValueError(\n                            f\"Dense mask shape {dense.shape[1:]} does not match \"\n                            f\"CompactMask image_shape {image_shape}.\"\n                        )\n                    compact_list.append(\n                        CompactMask.from_dense(dense, d.xyxy, image_shape)\n                    )","sourceCodeStart":2440,"sourceCodeEnd":2476,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/core.py#L2440-L2476","documentation":"Error \"Cannot merge CompactMask objects with different image shapes: {sorted(compact_image_shapes)}\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/detection/core.py:2458 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only merge CompactMask objects that share the same image_shape; check cm._image_shape for each before merging.","If the masks come from images of different sizes, resize or pad them to a common image_shape first."],"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"}