Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

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.py
index 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可以fallback
os.environ['NO_ALBUMENTATIONS_UPDATE'] = '1' # 禁止albumentations检查更新
+LAYOUT_BASE_BATCH_SIZE = 1
MFR_BASE_BATCH_SIZE = 16
OCR_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.py
index 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 = 1
MFR_BASE_BATCH_SIZE = 16
OCR_DET_BASE_BATCH_SIZE = 8
TABLE_ORI_CLS_BATCH_SIZE = 16
@@ -319,7 +319,8 @@ class BatchAnalyze:
# pp-doclayout_v2
images_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)