opendatalab/MinerU · error · ValueError

backend: {backend} is not supported for resize.Supported bac

Error message

backend: {backend} is not supported for resize.Supported backends are 'cv2', 'pillow'

What it means

The mmcv-style imresize helper supports exactly two backends: 'cv2' and 'pillow'. Any other string (or a typo, or an unset global read as something else) raises ValueError listing the supported set. backend=None defaults to 'cv2'.

Source

Thrown at mineru/model/table/rec/unet_table/utils.py:277

        size (tuple[int]): Target size (w, h).
        return_scale (bool): Whether to return `w_scale` and `h_scale`.
        interpolation (str): Interpolation method, accepted values are
            "nearest", "bilinear", "bicubic", "area", "lanczos" for 'cv2'
            backend, "nearest", "bilinear" for 'pillow' backend.
        out (ndarray): The output destination.
        backend (str | None): The image resize backend type. Options are `cv2`,
            `pillow`, `None`. If backend is None, the global imread_backend
            specified by ``mmcv.use_backend()`` will be used. Default: None.

    Returns:
        tuple | ndarray: (`resized_img`, `w_scale`, `h_scale`) or
        `resized_img`.
    """
    h, w = img.shape[:2]
    if backend is None:
        backend = "cv2"
    if backend not in ["cv2", "pillow"]:
        raise ValueError(
            f"backend: {backend} is not supported for resize."
            f"Supported backends are 'cv2', 'pillow'"
        )

    if backend == "pillow":
        assert img.dtype == np.uint8, "Pillow backend only support uint8 type"
        pil_image = Image.fromarray(img)
        pil_image = pil_image.resize(size, pillow_interp_codes[interpolation])
        resized_img = np.array(pil_image)
    else:
        resized_img = cv2.resize(
            img, size, dst=out, interpolation=cv2_interp_codes[interpolation]
        )
    if not return_scale:
        return resized_img
    else:
        w_scale = size[0] / w
        h_scale = size[1] / h

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Use exactly 'cv2' or 'pillow' (lowercase), or pass None for the cv2 default.
  2. Check the call signature to ensure backend is not receiving the interpolation argument.
  3. For torch-based resizing, do it before calling this helper.

Example fix

# before
out = resize_img(img, (w, h), backend='Pillow')

# after
out = resize_img(img, (w, h), backend='pillow')
Defensive patterns

Strategy: validation

Validate before calling

backend = (backend or 'cv2').lower()
assert backend in ('cv2', 'pillow'), f'bad backend {backend!r}'

Type guard

def is_supported_backend(b) -> bool:
    return b is None or (isinstance(b, str) and b.lower() in ('cv2', 'pillow'))

Prevention

When it happens

Trigger: Calling imresize-like resize utilities in unet_table with backend='PIL' (wrong case), backend='torch', or passing the interpolation string in the backend slot by argument mix-up.

Common situations: Porting mmcv code that used custom backends, case-sensitive config values from YAML, or positional-argument order mistakes.

Related errors


AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14). Data as JSON: /api/errors/e58854e44a20f7c9. Report an issue: GitHub.