opendatalab/MinerU · error · LoadImageError

{type(img)} is not supported!

Error message

{type(img)} is not supported!

What it means

load_img's terminal branch: the value is not str/Path, bytes, or ndarray, so it is not supported. In normal flow __call__ already rejects such types, so this fires mainly when load_img is called directly or when InputType was widened inconsistently.

Source

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

        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)))
            return img

        if isinstance(img, np.ndarray):
            return img

        raise LoadImageError(f"{type(img)} is not supported!")

    def convert_img(self, img: np.ndarray):
        if img.ndim == 2:
            return cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

        if img.ndim == 3:
            channel = img.shape[2]
            if channel == 1:
                return cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

            if channel == 2:
                return self.cvt_two_to_three(img)

            if channel == 4:
                return self.cvt_four_to_three(img)

            if channel == 3:
                return cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Call the loader instance (__call__) instead of load_img: img = load_image(pil_or_path).
  2. Convert before calling load_img directly: np.asarray(pil_img) for PIL, .cpu().numpy() for tensors.

Example fix

# before
img = loader.load_img(pil_image)  # PIL not handled in load_img

# after
img = loader(pil_image)  # go through __call__
Defensive patterns

Strategy: type-guard

Validate before calling

assert hasattr(loader, '__call__')
img = loader(img)  # never call loader.load_img directly

Type guard

def goes_through_call(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: Subclass or caller invoking load_img() directly with a PIL Image (not handled in load_img!), torch tensor, or other object, bypassing __call__.

Common situations: Refactors that call the internal method instead of __call__, or passing PIL Images assuming the str/bytes branches cover them.

Related errors


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