{"record":{"id":"68768b2fbc911605","repo":"opendatalab/MinerU","slug":"images-mfd-res-and-images-must-have-the-same-lengt-68768b","errorCode":null,"errorMessage":"images_mfd_res and images must have the same length.","messagePattern":"images_mfd_res and images must have the same length\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mineru/model/mfr/unimernet/Unimernet.py","lineNumber":124,"sourceCode":"        return self.batch_predict(\n            [mfd_res],\n            [image],\n            batch_size=batch_size,\n            interline_enable=interline_enable,\n        )[0]\n\n    def batch_predict(\n        self,\n        images_mfd_res: list,\n        images: list,\n        batch_size: int = 64,\n        interline_enable: bool = True,\n    ) -> list:\n        if not images_mfd_res:\n            return []\n\n        if len(images_mfd_res) != len(images):\n            raise ValueError(\"images_mfd_res and images must have the same length.\")\n\n        images_formula_list = []\n        mf_image_list = []\n        backfill_list = []\n        image_info = []\n\n        for mfd_res, image in zip(images_mfd_res, images):\n            formula_list, crop_targets = self._build_formula_items(\n                mfd_res,\n                image,\n                interline_enable=interline_enable,\n            )\n\n            for formula_item, (xmin, ymin, xmax, ymax) in crop_targets:\n                bbox_img = image[ymin:ymax, xmin:xmax]\n                area = (xmax - xmin) * (ymax - ymin)\n\n                curr_idx = len(mf_image_list)","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/opendatalab/MinerU/blob/4fe4bde114a23ee5dd637eae99b767f4669bf58c/mineru/model/mfr/unimernet/Unimernet.py#L106-L142","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Build both lists in a single loop over pages so indexes stay aligned.","If MFD results are missing for a page, insert an empty list [] rather than skipping, so lengths match.","Log len(images_mfd_res) and len(images) right before the call to find where they diverge."],"exampleFix":"# before\nimages_mfd_res = [r for r in all_res if r]  # drops empty pages\nbatch_predict(images_mfd_res, images)\n\n# after\nimages_mfd_res = [r if r else [] for r in all_res]  # keep alignment\nbatch_predict(images_mfd_res, images)","handlingStrategy":"validation","validationCode":"if len(images_mfd_res) != len(images):\n    raise ValueError(f'length mismatch: mfd={len(images_mfd_res)} images={len(images)}')\nresult = model.batch_predict(images_mfd_res, images)","typeGuard":null,"tryCatchPattern":"try:\n    result = model.batch_predict(mfd_res, images)\nexcept ValueError as e:\n    if 'same length' in str(e):\n        n = min(len(mfd_res), len(images))\n        result = model.batch_predict(mfd_res[:n], images[:n])  # or fix alignment and rerun\n    else:\n        raise","preventionTips":["Build parallel lists in one loop over pages.","Represent missing MFD results as [] instead of skipping entries.","Assert equal lengths in debug logging before every batch_predict call."],"tags":["api-contract","formula-recognition","validation"],"backgroundTag":null,"analyzedSha":"4fe4bde114a23ee5dd637eae99b767f4669bf58c","analyzedAt":"2026-08-14T21:29:18.456Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}