{"record":{"id":"38f74df56893c98d","repo":"roboflow/supervision","slug":"overlap-wh-must-be-a-non-negative-integer-recei","errorCode":null,"errorMessage":"`overlap_wh` must be a non negative integer. Received: {overlap_wh}","messagePattern":"`overlap_wh` must be a non negative integer\\. Received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/tools/inference_slicer.py","lineNumber":673,"sourceCode":"            if width <= 0 or height <= 0:\n                raise ValueError(\n                    f\"`slice_wh` values must be positive. Received: {slice_wh}\"\n                )\n            return width, height\n\n        raise ValueError(\n            \"`slice_wh` must be an int or a tuple of two positive integers \"\n            \"(slice_w, slice_h). \"\n            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        )","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/tools/inference_slicer.py#L655-L691","documentation":"Raised by InferenceSlicer._normalize_overlap_wh when the overlap_wh parameter passed as a plain int is negative. overlap_wh controls how many pixels adjacent inference slices overlap so objects on slice borders are still detected; a negative overlap has no meaning and would corrupt slice-offset generation.","triggerScenarios":"Calling InferenceSlicer(slice_wh=(512, 512), overlap_wh=-16) or passing any negative int as overlap_wh to the InferenceSlicer constructor.","commonSituations":"Copy-pasting a negative padding/margin value from other config into overlap_wh; sign errors when computing overlap programmatically (e.g. overlap = min_dim - margin going below zero); confusing overlap (must be >= 0) with stride/step offsets.","solutions":["Pass a non-negative integer, e.g. overlap_wh=16.","If computing overlap dynamically, clamp it: max(0, computed_overlap).","If you need per-axis overlap, pass a tuple of two non-negative ints instead, e.g. overlap_wh=(16, 32).","Check that overlap_wh is smaller than the corresponding slice_wh dimension so slices still advance."],"exampleFix":"# before\nslicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=-16)\n\n# after\nslicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=16)","handlingStrategy":"validation","validationCode":"overlap = int(user_overlap)\nif overlap < 0:\n    raise ValueError(f\"overlap_wh must be >= 0, got {overlap}\")\nslicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=max(0, overlap))","typeGuard":"def is_valid_overlap(overlap: int | tuple[int, int]) -> bool:\n    if isinstance(overlap, int):\n        return overlap >= 0\n    return (\n        isinstance(overlap, tuple)\n        and len(overlap) == 2\n        and all(isinstance(v, int) and v >= 0 for v in overlap)\n    )","tryCatchPattern":null,"preventionTips":["Validate slicer config once at startup, not per frame.","Keep overlap_wh below the corresponding slice_wh dimension.","Clamp programmatically computed overlaps with max(0, value)."],"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"}