{"record":{"id":"87777e119e9136b6","repo":"roboflow/supervision","slug":"overlap-values-must-be-greater-than-or-equal-to-0","errorCode":null,"errorMessage":"Overlap values must be greater than or equal to 0. Received: {overlap_wh}","messagePattern":"Overlap values must be greater than or equal to 0\\. Received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/tools/inference_slicer.py","lineNumber":766,"sourceCode":"        y_max = np.clip(y_min + slice_height, 0, image_height)\n\n        offsets: npt.NDArray[Any] = np.stack(\n            [x_min, y_min, x_max, y_max],\n            axis=-1,\n        ).reshape(-1, 4)\n\n        return offsets\n\n    @staticmethod\n    def _validate_overlap(\n        slice_wh: tuple[int, int],\n        overlap_wh: tuple[int, int],\n    ) -> None:\n        overlap_w, overlap_h = overlap_wh\n        slice_w, slice_h = slice_wh\n\n        if overlap_w < 0 or overlap_h < 0:\n            raise ValueError(\n                \"Overlap values must be greater than or equal to 0. \"\n                f\"Received: {overlap_wh}\"\n            )\n\n        if overlap_w >= slice_w or overlap_h >= slice_h:\n            raise ValueError(\n                \"`overlap_wh` must be smaller than `slice_wh` in both dimensions \"\n                f\"to keep a positive stride. Received overlap_wh={overlap_wh}, \"\n                f\"slice_wh={slice_wh}.\"\n            )\n","sourceCodeStart":748,"sourceCodeEnd":777,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/tools/inference_slicer.py#L748-L777","documentation":"Raised by InferenceSlicer._validate_overlap when either component of overlap_wh is negative. Slice overlap is a pixel count shared between adjacent tiles and must be zero or positive; negative overlap would mean tiles skip pixels of the image. Note _normalize_overlap_wh already rejects negative ints and tuples, so reaching this check usually means the values were passed already-normalized or bypassed normalization.","triggerScenarios":"Computing overlap dynamically (e.g. overlap = slice_wh - stride) that goes negative when stride exceeds slice size; calling _validate_overlap directly with negative entries; a custom subclass skipping _normalize_overlap_wh.","commonSituations":"Stride-based config converted to overlap with wrong operand order (overlap = stride - slice_wh instead of slice_wh - stride); arithmetic on config values that underflows for small slices.","solutions":["Use overlap_wh >= 0 in both components; 0 means no overlap between tiles.","Fix the conversion formula: overlap = max(0, slice_wh - stride).","Pass overlap through the constructor (int or 2-tuple) so normalization handles validation."],"exampleFix":"# before\noverlap = stride - slice_wh  # negative when stride > slice_wh\nslicer = sv.InferenceSlicer(callback=cb, slice_wh=slice_wh, overlap_wh=(overlap, overlap))\n\n# after\noverlap = max(0, slice_wh - stride)\nslicer = sv.InferenceSlicer(callback=cb, slice_wh=slice_wh, overlap_wh=(overlap, overlap))","handlingStrategy":"validation","validationCode":"overlap_w, overlap_h = (max(0, int(v)) for v in (overlap_w, overlap_h))\nslicer = sv.InferenceSlicer(callback=cb, slice_wh=(slice_w, slice_h), overlap_wh=(overlap_w, overlap_h))","typeGuard":"def is_non_negative_overlap(overlap_wh) -> bool:\n    return all(v >= 0 for v in overlap_wh)","tryCatchPattern":null,"preventionTips":["Derive overlap from stride as max(0, slice - stride), never the reverse subtraction.","Keep overlap params non-negative ints at the config boundary."],"tags":["inference-slicer","overlap","validation","valueerror"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}