Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat: update formula label handling and improve layout processing in pp_doclayoutv2
myhloli1c47bfeaaa90
diff --git a/mineru/backend/pipeline/batch_analyze.py b/mineru/backend/pipeline/batch_analyze.pyindex 819a0fd8..00a9a4e7 100644--- a/mineru/backend/pipeline/batch_analyze.py+++ b/mineru/backend/pipeline/batch_analyze.py@@ -56,7 +56,7 @@ class BatchAnalyze:for layout_res in images_layout_res:page_formula_res = []for res in layout_res:- if res.get("label") == "formula":+ if res.get("label") in ["display_formula", "inline_formula"]:res.setdefault("latex", "")page_formula_res.append(res)images_mfd_res.append(page_formula_res)@@ -74,6 +74,10 @@ class BatchAnalyze:images_mfd_res[image_index], images_formula_list[image_index]):formula_res["latex"] = formula_with_latex.get("latex", "")+ else:+ for layout_res in images_layout_res:+ # 移除所有的"inline_formula"+ layout_res[:] = [res for res in layout_res if res.get("label") != "inline_formula"]# 清理显存clean_vram(self.model.device, vram_threshold=8)diff --git a/mineru/model/layout/pp_doclayoutv2.py b/mineru/model/layout/pp_doclayoutv2.pyindex 06fe2de7..76d50fe5 100644--- a/mineru/model/layout/pp_doclayoutv2.py+++ b/mineru/model/layout/pp_doclayoutv2.py@@ -33,17 +33,17 @@ PP_DOCLAYOUT_V2_LABELS = ["aside_text", # 2"chart", # 3"content", # 4- "formula", # 5 display+ "display_formula", # 5"doc_title", # 6"figure_title", # 7"footer", # 8- "footer", # 9 image+ "footer_image", # 9"footnote", # 10"formula_number", # 11"header", # 12- "header", # 13 image+ "header_image", # 13"image", # 14- "formula", # 15 inline+ "inline_formula", # 15"number", # 16"paragraph_title", # 17"reference", # 18@@ -51,7 +51,7 @@ PP_DOCLAYOUT_V2_LABELS = ["seal", # 20"table", # 21"text", # 22- "text", # 23 vertical+ "vertical_text", # 23"vision_footnote", # 24]@@ -62,17 +62,17 @@ DEFAULT_CLASS_THRESHOLDS = [0.5, # 2 aside_text0.5, # 3 chart0.5, # 4 content- 0.4, # 5 formula+ 0.4, # 5 display_formula0.4, # 6 doc_title0.5, # 7 figure_title0.5, # 8 footer- 0.5, # 9 footer+ 0.5, # 9 footer_image0.5, # 10 footnote0.5, # 11 formula_number0.5, # 12 header- 0.5, # 13 header+ 0.5, # 13 header_image0.5, # 14 image- 0.4, # 15 formula+ 0.4, # 15 inline_formula0.5, # 16 number0.4, # 17 paragraph_title0.5, # 18 reference@@ -80,7 +80,7 @@ DEFAULT_CLASS_THRESHOLDS = [0.45, # 20 seal0.5, # 21 table0.4, # 22 text- 0.4, # 23 text+ 0.4, # 23 vertical_text0.5, # 24 vision_footnote]@@ -91,7 +91,7 @@ DEFAULT_CLASS_ORDER = [14, # 2 aside_text1, # 3 chart5, # 4 content- 7, # 5 formula+ 7, # 5 display_formula8, # 6 doc_title6, # 7 figure_title11, # 8 footer@@ -99,9 +99,9 @@ DEFAULT_CLASS_ORDER = [9, # 10 footnote13, # 11 formula_number10, # 12 header- 10, # 13 header+ 10, # 13 header_image1, # 14 image- 2, # 15 formula+ 2, # 15 inline_formula3, # 16 number0, # 17 paragraph_title2, # 18 reference@@ -109,7 +109,7 @@ DEFAULT_CLASS_ORDER = [12, # 20 seal1, # 21 table2, # 22 text- 15, # 23 text+ 15, # 23 vertical_text6, # 24 vision_footnote]@@ -984,6 +984,8 @@ class PPDocLayoutV2LayoutModel:return resultsdef _label_id_to_label_name(self, label_id: int) -> str:+ if 0 <= label_id < len(PP_DOCLAYOUT_V2_LABELS):+ return PP_DOCLAYOUT_V2_LABELS[label_id]return str(self.config.id2label.get(label_id, self.config.id2label.get(str(label_id), label_id)))@staticmethod@@ -1248,7 +1250,7 @@ if __name__ == "__main__":os.path.join(auto_download_and_get_model_root_path(ModelPath.pp_doclayout_v2), ModelPath.pp_doclayout_v2))- args.image = "/Users/myhloli/pdf/png/academic_paper_img_formula.png"+ args.image = "/Users/myhloli/pdf/png/table_image2.png"model = PPDocLayoutV2LayoutModel(weight=args.model,diff --git a/mineru/utils/model_utils.py b/mineru/utils/model_utils.pyindex fd9d9f4c..01467e18 100644--- a/mineru/utils/model_utils.py+++ b/mineru/utils/model_utils.py@@ -26,6 +26,7 @@ TEXT_REGION_LABELS = {"paragraph_title","reference_content","text",+ "vertical_text","vision_footnote",}@@ -155,7 +156,7 @@ def get_res_list_from_layout_res(layout_res, overlap_threshold=0.8):for i, res in enumerate(layout_res):label = res.get("label")- if label == "formula":+ if label in ["display_formula", "inline_formula"]:xmin, ymin, xmax, ymax = _get_bbox(res)single_page_mfdetrec_res.append({"bbox": [xmin, ymin, xmax, ymax],