roboflow/supervision · error · ValueError
`slice_wh` must be a positive integer. Received: {slice_wh}
Error message
`slice_wh` must be a positive integer. Received: {slice_wh} What it means
Raised by InferenceSlicer._normalize_slice_wh when slice_wh is an int that is zero or negative. The int form means 'square slices of this pixel size'; a non-positive size cannot tile any image, so construction fails.
Source
Thrown at src/supervision/detection/tools/inference_slicer.py:648
"full-resolution image.",
category=SupervisionWarnings,
stacklevel=2,
)
return [
move_detections(
detections=det, offset=offset[:2], resolution_wh=resolution_wh
)
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}"
)
View on GitHub (pinned to 7f254d9784)
Solutions
- Pass a positive pixel size, e.g. slice_wh=512.
- Guard computed sizes: slice_wh = max(1, computed) — though realistically pick a real tile size like 320-1024.
- Validate required config fields at load time instead of relying on constructor failure.
Example fix
# before
slicer = sv.InferenceSlicer(callback=cb, slice_wh=cfg.get('slice', 0))
# after
slice_size = cfg.get('slice') or 512
slicer = sv.InferenceSlicer(callback=cb, slice_size if isinstance(slice_size, tuple) else int(slice_size)) Defensive patterns
Strategy: validation
Validate before calling
slice_wh = int(cfg.get('slice_wh') or 512)
assert slice_wh > 0, 'slice_wh must be a positive pixel size'
slicer = sv.InferenceSlicer(callback=cb, slice_wh=slice_wh) Type guard
def is_positive_int(v) -> bool:
return isinstance(v, int) and v > 0 Prevention
- Do not use 0 as an 'unset' sentinel for tile size — validate required config at load time.
- Pick tile sizes from the standard range (320, 512, 640, 1024) matching your model input.
When it happens
Trigger: Passing slice_wh=0 or a negative int, typically from a computed value (e.g. target_size // scale that floors to 0) or an unset config default of 0.
Common situations: Downscaling math that produces 0 for very large divisors; config schemas where 0 is the 'unset' sentinel; CLI defaults leaking through.
Related errors
- `slice_wh` must be an int or a tuple of two positive integer
- `overlap_wh` must be an int or a tuple of two non negative i
- `thread_workers` must be a positive integer. Received: {thre
- `batch_size` must be a positive integer. Received: {batch_si
- `slice_wh` values must be positive. Received: {slice_wh}
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/ebb819808ada8cbc.
Report an issue: GitHub.