opendatalab/MinerU · error · LoadImageError

The img type {type(img)} does not in {InputType.__args__}

Error message

The img type {type(img)} does not in {InputType.__args__}

What it means

LoadImage.__call__ validates the input against the InputType union (str, Path, bytes, np.ndarray, PIL Image). Passing any other type — torch tensor, dict, list, None — raises LoadImageError listing the received type and the accepted set.

Source

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

            raise ONNXRuntimeError(error_info) from e

    def get_input_names(self) -> List[str]:
        return [v.name for v in self.session.get_inputs()]


class ONNXRuntimeError(Exception):
    pass


class LoadImage:
    def __init__(
        self,
    ):
        pass

    def __call__(self, img: InputType) -> np.ndarray:
        if not isinstance(img, InputType.__args__):
            raise LoadImageError(
                f"The img type {type(img)} does not in {InputType.__args__}"
            )

        img = self.load_img(img)
        img = self.convert_img(img)
        return img

    def load_img(self, img: InputType) -> np.ndarray:
        if isinstance(img, (str, Path)):
            self.verify_exist(img)
            try:
                img = np.array(Image.open(img))
            except UnidentifiedImageError as e:
                raise LoadImageError(f"cannot identify image file {img}") from e
            return img

        if isinstance(img, bytes):
            img = np.array(Image.open(BytesIO(img)))

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Convert tensors: arr = t.detach().cpu().numpy().astype(np.uint8).
  2. None-check optional inputs before calling the loader.
  3. For lists, loop and load each item individually.

Example fix

# before
img = load_image(tensor_crop)

# after
img = load_image(tensor_crop.detach().cpu().numpy())
Defensive patterns

Strategy: type-guard

Validate before calling

from PIL import Image
import numpy as np
ACCEPTED = (str, Path, bytes, np.ndarray, Image.Image)
if not isinstance(img, ACCEPTED):
    img = np.asarray(img) if hasattr(img, '__array__') else None

Type guard

def is_loader_input(img) -> bool:
    from PIL import Image
    import numpy as np
    return isinstance(img, (str, Path, bytes, np.ndarray, Image.Image))

Prevention

When it happens

Trigger: Calling the loader with a torch.Tensor, a list of images, or None (e.g. a failed upstream crop returned None).

Common situations: Bridging PyTorch-based layout detection outputs into this OpenCV-based table pipeline, or optional fields that silently become None.

Related errors


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