roboflow/supervision · error · ValueError
`slice_wh` must be an int or a tuple of two positive integer
Error message
`slice_wh` must be an int or a tuple of two positive integers (slice_w, slice_h). Received: {slice_wh} What it means
Raised by InferenceSlicer's _normalize_slice_wh when slice_wh is neither an int nor a 2-tuple of ints. The slicer tiles the image into cells of (slice_w, slice_h); any other type (float, string, list, 1- or 3-tuple) has no defined meaning, so it is rejected during construction.
Source
Thrown at src/supervision/detection/tools/inference_slicer.py:661
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. "
f"Received: {overlap_wh}"
)
return overlap_wh, overlap_wh
if isinstance(overlap_wh, tuple) and len(overlap_wh) == 2:View on GitHub (pinned to 7f254d9784)
Solutions
- Pass an int (slice_wh=512) or an int 2-tuple (slice_wh=(512, 384)).
- Coerce config values at load time: tuple(int(v) for v in cfg['slice_wh']) if it is a sequence, else int(cfg['slice_wh']).
- Validate config schema before constructing the slicer.
Example fix
# before slicer = sv.InferenceSlicer(callback=cb, slice_wh=[512, 512]) # ValueError # after slicer = sv.InferenceSlicer(callback=cb, slice_wh=(512, 512))
Defensive patterns
Strategy: validation
Validate before calling
def normalize_slice_wh(v):
if isinstance(v, (list, tuple)):
v = tuple(int(x) for x in v)
else:
v = int(v)
return v
slicer = sv.InferenceSlicer(callback=cb, slice_wh=normalize_slice_wh(cfg['slice_wh'])) Type guard
def is_valid_slice_wh(v) -> bool:
if isinstance(v, int):
return v > 0
return isinstance(v, tuple) and len(v) == 2 and all(isinstance(x, int) and x > 0 for x in v) Prevention
- Coerce config-sourced numeric params to int at load time.
- Schema-validate config files (type, range) before constructing InferenceSlicer.
When it happens
Trigger: Constructing sv.InferenceSlicer(callback=..., slice_wh=512.0), slice_wh="512", slice_wh=[512, 512], or slice_wh=(512, 512, 3).
Common situations: slice_wh read from JSON/YAML config arrives as float or list; CLI argument parsing yields a string; accidentally passing image resolution or a channel-count tuple.
Related errors
- `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` must be a positive integer. Received: {slice_wh}
- `slice_wh` values must be positive. Received: {slice_wh}
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/bf624c78da7d80ce.
Report an issue: GitHub.