roboflow/supervision · error · ValueError

`overlap_wh` must be smaller than `slice_wh` in both dimensi

Error message

`overlap_wh` must be smaller than `slice_wh` in both dimensions to keep a positive stride. Received overlap_wh={overlap_wh}, slice_wh={slice_wh}.

What it means

Raised by InferenceSlicer._validate_overlap when overlap_wh is greater than or equal to slice_wh in either dimension. Slice offsets advance by (slice_wh - overlap_wh) per tile; if overlap meets or exceeds the slice size the stride is zero or negative, which would produce an infinite or degenerate tiling, so it is rejected.

Source

Thrown at src/supervision/detection/tools/inference_slicer.py:772

        return offsets

    @staticmethod
    def _validate_overlap(
        slice_wh: tuple[int, int],
        overlap_wh: tuple[int, int],
    ) -> None:
        overlap_w, overlap_h = overlap_wh
        slice_w, slice_h = slice_wh

        if overlap_w < 0 or overlap_h < 0:
            raise ValueError(
                "Overlap values must be greater than or equal to 0. "
                f"Received: {overlap_wh}"
            )

        if overlap_w >= slice_w or overlap_h >= slice_h:
            raise ValueError(
                "`overlap_wh` must be smaller than `slice_wh` in both dimensions "
                f"to keep a positive stride. Received overlap_wh={overlap_wh}, "
                f"slice_wh={slice_wh}."
            )

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Choose overlap strictly smaller than the slice in both dimensions, e.g. slice_wh=(512, 512), overlap_wh=(128, 128) — 20-25% of the slice is a common starting point.
  2. If you intended full-image inference without tiling, do not use InferenceSlicer — call the callback on the whole image.
  3. Add a config assertion: assert 0 <= overlap_w < slice_w and 0 <= overlap_h < slice_h.

Example fix

# before
slicer = sv.InferenceSlicer(callback=cb, slice_wh=640, overlap_wh=640)  # ValueError

# after
slicer = sv.InferenceSlicer(callback=cb, slice_wh=640, overlap_wh=128)
Defensive patterns

Strategy: validation

Validate before calling

assert 0 <= overlap_w < slice_w and 0 <= overlap_h < slice_h, 'overlap must be < slice in both axes'
slicer = sv.InferenceSlicer(callback=cb, slice_wh=(slice_w, slice_h), overlap_wh=(overlap_w, overlap_h))

Type guard

def is_valid_overlap_vs_slice(slice_wh, overlap_wh) -> bool:
    (sw, sh), (ow, oh) = slice_wh, overlap_wh
    return 0 <= ow < sw and 0 <= oh < sh

Prevention

When it happens

Trigger: Passing overlap_wh=(640, 640) with slice_wh=(640, 640); any configuration where overlap_w >= slice_w or overlap_h >= slice_h, e.g. copying the slice size into the overlap parameter or a ratio/target-size mix-up.

Common situations: Setting overlap equal to slice size expecting 'maximum coverage'; config templates where the same number is pasted into both fields; computing overlap as a percentage of the image but sized in slice pixels.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/283439aa7239e40e. Report an issue: GitHub.