opendatalab/MinerU · error · LoadImageError

cannot identify image file {img}

Error message

cannot identify image file {img}

What it means

When loading from a str/Path, PIL raises UnidentifiedImageError for files whose bytes are not a recognizable image format; the loader re-wraps it as LoadImageError('cannot identify image file <path>'). Corrupted, truncated, or non-image files hit this even though the path exists.

Source

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

        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)))
            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:

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Verify the file: file table.png and check size > 0.
  2. Re-download or re-export the image.
  3. Upgrade Pillow and install plugin extras (pip install -U 'pillow[plugins]' or pillow-heif etc.) for exotic formats.
  4. Convert the image to PNG/JPEG with an external tool if the format is unsupported.

Example fix

# before
img = load_image('page_3.png')  # actually HTML error page

# after
# validate magic first
with open(p,'rb') as f: head = f.read(8)
if not head.startswith((b'\\x89PNG', b'\\xff\\xd8')):
    raise ValueError(f'{p} is not a decodable image')
img = load_image(p)
Defensive patterns

Strategy: try-catch

Validate before calling

def is_decodable_image(p) -> bool:
    try:
        with Image.open(p) as im:
            im.verify()
        return True
    except Exception:
        return False

Try / catch

try:
    img = load_image(path)
except LoadImageError as e:
    if 'cannot identify image file' in str(e):
        logger.warning('bad image %s; skipping', path)
        return None  # skip-and-continue for batch ingestion
    raise

Prevention

When it happens

Trigger: Image.open() on a 0-byte file, a file with a wrong extension (e.g. WebP renamed .png with old Pillow lacking WebP support), a truncated download, or an HTML error page saved as an image.

Common situations: Interrupted downloads, disk-full partial writes, exotic formats (TIFF variants, JXL) not enabled in the installed Pillow build.

Related errors


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