roboflow/supervision · error · ValueError

`overlap_wh` values must be non negative. Received: {overlap

Error message

`overlap_wh` values must be non negative. Received: {overlap_wh}

What it means

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.

Source

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

            f"Received: {slice_wh}"
        )

    @staticmethod
    def _normalize_overlap_wh(
        overlap_wh: int | tuple[int, int],
    ) -> tuple[int, int]:
        if isinstance(overlap_wh, int):
            if overlap_wh < 0:
                raise ValueError(
                    "`overlap_wh` must be a non negative integer. "
                    f"Received: {overlap_wh}"
                )
            return overlap_wh, overlap_wh

        if isinstance(overlap_wh, tuple) and len(overlap_wh) == 2:
            overlap_w, overlap_h = overlap_wh
            if overlap_w < 0 or overlap_h < 0:
                raise ValueError(
                    f"`overlap_wh` values must be non negative. Received: {overlap_wh}"
                )
            return overlap_w, overlap_h

        raise ValueError(
            "`overlap_wh` must be an int or a tuple of two non negative integers "
            "(overlap_w, overlap_h). "
            f"Received: {overlap_wh}"
        )

    @staticmethod
    def _generate_offset(
        resolution_wh: tuple[int, int],
        slice_wh: tuple[int, int],
        overlap_wh: tuple[int, int],
    ) -> npt.NDArray[Any]:
        """
        Generate bounding boxes defining the coordinates of image slices with overlap.

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Make both tuple components non-negative, e.g. overlap_wh=(16, 32).
  2. Clamp computed values: overlap_wh=(max(0, w), max(0, h)).
  3. Verify each component is smaller than its slice_wh counterpart to avoid non-advancing slices.

Example fix

# before
slicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=(-10, 32))

# after
slicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=(10, 32))
Defensive patterns

Strategy: validation

Validate before calling

overlap_wh = tuple(max(0, v) for v in overlap_wh)
slicer = InferenceSlicer(slice_wh=(512, 512), overlap_wh=overlap_wh)

Type guard

def is_valid_overlap_wh(overlap_wh: tuple[int, int]) -> bool:
    return len(overlap_wh) == 2 and all(v >= 0 for v in overlap_wh)

Prevention

When it happens

Trigger: Calling InferenceSlicer(overlap_wh=(-10, 20)), InferenceSlicer(overlap_wh=(0, -5)), or any constructor call where one tuple element is negative.

Common situations: 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.

Related errors


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