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: adjust layout base batch size and improve dynamic batch sizing in predictions
myhlolid1369ea95387
diff --git a/mineru/backend/hybrid/hybrid_analyze.py b/mineru/backend/hybrid/hybrid_analyze.pyindex c8fe7751..32d42333 100644--- a/mineru/backend/hybrid/hybrid_analyze.py+++ b/mineru/backend/hybrid/hybrid_analyze.py@@ -41,6 +41,7 @@ from mineru.utils.pdfium_guard import (os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 让mps可以fallbackos.environ['NO_ALBUMENTATIONS_UPDATE'] = '1' # 禁止albumentations检查更新+LAYOUT_BASE_BATCH_SIZE = 1MFR_BASE_BATCH_SIZE = 16OCR_DET_BASE_BATCH_SIZE = 8@@ -303,7 +304,10 @@ def _process_ocr_and_formulas(# 在进行`行内`公式检测和识别前,先将图像中的图片、表格、`行间`公式区域mask掉np_images = mask_image_regions(np_images, model_list)# 使用layout模型提供行内公式检测框- images_layout_res = hybrid_pipeline_model.layout_model.batch_predict(np_images, batch_size=1)+ images_layout_res = hybrid_pipeline_model.layout_model.batch_predict(+ np_images,+ batch_size=min(8, batch_radio * LAYOUT_BASE_BATCH_SIZE),+ )images_mfd_res = _build_inline_formula_inputs(images_layout_res)# 公式识别inline_formula_list = hybrid_pipeline_model.mfr_model.batch_predict(diff --git a/mineru/backend/pipeline/batch_analyze.py b/mineru/backend/pipeline/batch_analyze.pyindex bc7f9ad6..88ae0dfd 100644--- a/mineru/backend/pipeline/batch_analyze.py+++ b/mineru/backend/pipeline/batch_analyze.py@@ -25,7 +25,7 @@ from ...utils.ocr_utils import ()from ...utils.pdf_image_tools import get_crop_np_img-LAYOUT_BASE_BATCH_SIZE = 4+LAYOUT_BASE_BATCH_SIZE = 1MFR_BASE_BATCH_SIZE = 16OCR_DET_BASE_BATCH_SIZE = 8TABLE_ORI_CLS_BATCH_SIZE = 16@@ -319,7 +319,8 @@ class BatchAnalyze:# pp-doclayout_v2images_layout_res += self.model.layout_model.batch_predict(- pil_images, LAYOUT_BASE_BATCH_SIZE+ pil_images,+ batch_size=min(8, self.batch_ratio * LAYOUT_BASE_BATCH_SIZE))# 清理显存clean_vram(self.model.device, vram_threshold=8)