opendatalab/MinerU · error · ValueError

images_mfd_res and images must have the same length.

Error message

images_mfd_res and images must have the same length.

What it means

Unimernet's batch_predict zips images_mfd_res (per-page MFD detection results) against images (per-page images); they must be one-to-one. The ValueError fires when the two lists differ in length, which would silently drop or misalign formulas otherwise.

Source

Thrown at mineru/model/mfr/unimernet/Unimernet.py:124

        return self.batch_predict(
            [mfd_res],
            [image],
            batch_size=batch_size,
            interline_enable=interline_enable,
        )[0]

    def batch_predict(
        self,
        images_mfd_res: list,
        images: list,
        batch_size: int = 64,
        interline_enable: bool = True,
    ) -> list:
        if not images_mfd_res:
            return []

        if len(images_mfd_res) != len(images):
            raise ValueError("images_mfd_res and images must have the same length.")

        images_formula_list = []
        mf_image_list = []
        backfill_list = []
        image_info = []

        for mfd_res, image in zip(images_mfd_res, images):
            formula_list, crop_targets = self._build_formula_items(
                mfd_res,
                image,
                interline_enable=interline_enable,
            )

            for formula_item, (xmin, ymin, xmax, ymax) in crop_targets:
                bbox_img = image[ymin:ymax, xmin:xmax]
                area = (xmax - xmin) * (ymax - ymin)

                curr_idx = len(mf_image_list)

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Build both lists in a single loop over pages so indexes stay aligned.
  2. If MFD results are missing for a page, insert an empty list [] rather than skipping, so lengths match.
  3. Log len(images_mfd_res) and len(images) right before the call to find where they diverge.

Example fix

# before
images_mfd_res = [r for r in all_res if r]  # drops empty pages
batch_predict(images_mfd_res, images)

# after
images_mfd_res = [r if r else [] for r in all_res]  # keep alignment
batch_predict(images_mfd_res, images)
Defensive patterns

Strategy: validation

Validate before calling

if len(images_mfd_res) != len(images):
    raise ValueError(f'length mismatch: mfd={len(images_mfd_res)} images={len(images)}')
result = model.batch_predict(images_mfd_res, images)

Try / catch

try:
    result = model.batch_predict(mfd_res, images)
except ValueError as e:
    if 'same length' in str(e):
        n = min(len(mfd_res), len(images))
        result = model.batch_predict(mfd_res[:n], images[:n])  # or fix alignment and rerun
    else:
        raise

Prevention

When it happens

Trigger: Calling batch_predict(images_mfd_res=detection_results, images=pages) where detection_results came from an MFD model run on a filtered subset of pages (e.g. empty results dropped) while pages still contains every page, or vice versa.

Common situations: Building the two lists in separate loops with different skip conditions, reusing cached MFD results after the page list changed, or appending placeholder entries for failed pages on one side only.

Related errors


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