{"record":{"id":"dce1fed5e5ef381f","repo":"roboflow/supervision","slug":"dense-mask-shape-dense-shape-1-does-not-match","errorCode":null,"errorMessage":"Dense mask shape {dense.shape[1:]} does not match CompactMask image_shape {image_shape}.","messagePattern":"Dense mask shape (.+?) does not match CompactMask image_shape (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/core.py","lineNumber":2470,"sourceCode":"            # 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                    )\n            return CompactMask.merge(compact_list)\n\n        def stack_or_none(name: str) -> npt.NDArray[np.generic] | None:\n            values = [getattr(d, name) for d in detections_list]\n            if all(v is None for v in values):\n                return None\n            if any(v is None for v in values):\n                raise ValueError(f\"All or none of the '{name}' fields must be None\")\n            return cast(npt.NDArray[np.generic], np.hstack(values))\n\n        mask = cast(npt.NDArray[np.bool_] | CompactMask | None, stack_mask_or_none())\n        confidence = cast(npt.NDArray[np.floating] | None, stack_or_none(\"confidence\"))","sourceCodeStart":2452,"sourceCodeEnd":2488,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/core.py#L2452-L2488","documentation":"Error \"Dense mask shape {dense.shape[1:]} does not match CompactMask image_shape {image_shape}.\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/detection/core.py:2470 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure each dense mask's (H, W) matches the CompactMask image_shape before conversion.","Resize or crop the dense masks to the expected image_shape, or create the CompactMask with the matching shape."],"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-15T17:31:12.345Z"}