roboflow/supervision · error · ValueError

Both elements in resolution must be integers.

Error message

            Both elements in resolution must be integers.
            Got types ({type(w)}, {type(h)})
            

What it means

Raised by supervision.validators._validate_resolution when resolution is a 2-tuple but one or both elements are not Python ints (e.g. floats, numpy scalars, or strings). The library requires exact int types because downstream indexing/geometry assumes integer pixel dimensions.

Source

Thrown at src/supervision/validators/__init__.py:344

    remove_in="0.31.0",
)
def validate_keypoints_fields(
    xy: Any, class_id: Any, confidence: Any, data: dict[str, Any]
) -> None:
    void(xy, class_id, confidence, data)


def _validate_resolution(resolution: Any) -> tuple[int, int]:
    if not (isinstance(resolution, tuple) and len(resolution) == 2):
        raise ValueError(
            f"""
            resolution must be a tuple of two integers, got
            {type(resolution)} with value {resolution}
            """
        )
    w, h = resolution
    if not (isinstance(w, int) and isinstance(h, int)):
        raise ValueError(
            f"""
            Both elements in resolution must be integers.
            Got types ({type(w)}, {type(h)})
            """
        )
    if w <= 0 or h <= 0:
        raise ValueError(
            f"Both dimensions in resolution must be positive. Got ({w}, {h})."
        )
    return w, h


@deprecated(  # type: ignore[untyped-decorator]
    target=_validate_resolution,
    deprecated_in="0.29.0",
    remove_in="0.32.0",
)
def validate_resolution(resolution: Any) -> tuple[int, int]:

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Coerce to int: resolution=(int(w), int(h)).
  2. Use integer division or round when scaling: resolution=(w // 2, h // 2).
  3. Validate config values at load time if resolution comes from user-supplied YAML/JSON.

Example fix

# before
resolution = (w * scale, h * scale)  # floats -> ValueError

# after
resolution = (round(w * scale), round(h * scale))
Defensive patterns

Strategy: validation

Validate before calling

resolution = (int(resolution[0]), int(resolution[1]))
obj = SomeAPI(resolution=resolution)

Type guard

def is_int_resolution(resolution: tuple[Any, Any]) -> bool:
    return all(isinstance(v, int) for v in resolution)

Prevention

When it happens

Trigger: Passing resolution=(1920.0, 1080.0) after float math; passing np.int64 scalars from array operations like frame.shape-derived values wrapped in numpy types; passing ('1920', 1080).

Common situations: Computing scaled resolutions with float arithmetic (w * 0.5) and forgetting round(); values coming out of numpy arrays or config parsers (yaml/json give ints usually, but computed configs give floats).

Related errors


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