roboflow/supervision · error · ValueError

`slice_wh` values must be positive. Received: {slice_wh}

Error message

`slice_wh` values must be positive. Received: {slice_wh}

What it means

Raised by InferenceSlicer._normalize_slice_wh when slice_wh is a 2-tuple but one of its components (slice_w or slice_h) is zero or negative. Each component is a pixel size for tiling in its dimension and must be positive.

Source

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

            )
            for det, offset in zip(detections_in_slices, offsets)
        ]

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

        if isinstance(slice_wh, tuple) and len(slice_wh) == 2:
            width, height = slice_wh
            if width <= 0 or height <= 0:
                raise ValueError(
                    f"`slice_wh` values must be positive. Received: {slice_wh}"
                )
            return width, height

        raise ValueError(
            "`slice_wh` must be an int or a tuple of two positive integers "
            "(slice_w, slice_h). "
            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. "

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Make both components positive ints, e.g. slice_wh=(512, 384).
  2. Clamp per-axis computed sizes: (max(1, w), max(1, h)).
  3. Validate config keys individually before building the tuple.

Example fix

# before
slice_wh = (cfg['slice_w'], cfg.get('slice_h', 0))  # ValueError when slice_h missing

# after
slice_wh = (int(cfg['slice_w']), int(cfg['slice_h']))
Defensive patterns

Strategy: validation

Validate before calling

slice_wh = (int(cfg['slice_w']), int(cfg['slice_h']))
assert slice_wh[0] > 0 and slice_wh[1] > 0, 'both slice components must be positive'
slicer = sv.InferenceSlicer(callback=cb, slice_wh=slice_wh)

Type guard

def is_valid_slice_wh_tuple(v) -> bool:
    return isinstance(v, tuple) and len(v) == 2 and all(isinstance(x, int) and x > 0 for x in v)

Prevention

When it happens

Trigger: Passing slice_wh=(512, 0), (0, 0), or negative components; per-axis sizes computed from image dimensions where one axis divides down to 0.

Common situations: Aspect-ratio math that produces 0 for one axis (e.g. 2 * h - 2 * h_edge on thin strips); tuple built from two config keys where one is missing and defaults to 0.

Related errors


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