{"record":{"id":"66c5be0f554cf19a","repo":"roboflow/supervision","slug":"overlap-wh-values-must-be-non-negative-received","errorCode":null,"errorMessage":"`overlap_wh` values must be non negative. Received: {overlap_wh}","messagePattern":"`overlap_wh` values must be non negative\\. Received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/tools/inference_slicer.py","lineNumber":682,"sourceCode":"            f\"Received: {slice_wh}\"\n        )\n\n    @staticmethod\n    def _normalize_overlap_wh(\n        overlap_wh: int | tuple[int, int],\n    ) -> tuple[int, int]:\n        if isinstance(overlap_wh, int):\n            if overlap_wh < 0:\n                raise ValueError(\n                    \"`overlap_wh` must be a non negative integer. \"\n                    f\"Received: {overlap_wh}\"\n                )\n            return overlap_wh, overlap_wh\n\n        if isinstance(overlap_wh, tuple) and len(overlap_wh) == 2:\n            overlap_w, overlap_h = overlap_wh\n            if overlap_w < 0 or overlap_h < 0:\n                raise ValueError(\n                    f\"`overlap_wh` values must be non negative. Received: {overlap_wh}\"\n                )\n            return overlap_w, overlap_h\n\n        raise ValueError(\n            \"`overlap_wh` must be an int or a tuple of two non negative integers \"\n            \"(overlap_w, overlap_h). \"\n            f\"Received: {overlap_wh}\"\n        )\n\n    @staticmethod\n    def _generate_offset(\n        resolution_wh: tuple[int, int],\n        slice_wh: tuple[int, int],\n        overlap_wh: tuple[int, int],\n    ) -> npt.NDArray[Any]:\n        \"\"\"\n        Generate bounding boxes defining the coordinates of image slices with overlap.","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/tools/inference_slicer.py#L664-L700","documentation":"Raised by InferenceSlicer._normalize_overlap_wh when overlap_wh is a 2-tuple but at least one component (overlap_w or overlap_h) is negative. The tuple form allows different horizontal and vertical overlap between slices; negative components are rejected before offset generation.","triggerScenarios":"Calling InferenceSlicer(overlap_wh=(-10, 20)), InferenceSlicer(overlap_wh=(0, -5)), or any constructor call where one tuple element is negative.","commonSituations":"Mirroring signed offsets from a custom slicing config; arithmetic that derives overlap_w/overlap_h from image or slice sizes and underflows; mixing up (x, y) ordering with values from a source that uses signed margins.","solutions":["Make both tuple components non-negative, e.g. overlap_wh=(16, 32).","Clamp computed values: overlap_wh=(max(0, w), max(0, h)).","Verify each component is smaller than its slice_wh counterpart to avoid non-advancing slices."],"exampleFix":"# before\nslicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=(-10, 32))\n\n# after\nslicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=(10, 32))","handlingStrategy":"validation","validationCode":"overlap_wh = tuple(max(0, v) for v in overlap_wh)\nslicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=overlap_wh)","typeGuard":"def is_valid_overlap_wh(overlap_wh: tuple[int, int]) -> bool:\n    return len(overlap_wh) == 2 and all(v >= 0 for v in overlap_wh)","tryCatchPattern":null,"preventionTips":["Sanitize both tuple components before constructing InferenceSlicer.","Log the final overlap_wh used so misconfig is visible in debug output.","Keep slice/overlap config in one place and unit-test its invariants."],"tags":["inference-slicer","validation","configuration","valueerror"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}