Skip to content

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

feat: enhance VLM layout processing with image analysis toggle and sub-type handling

myhloli7424b889906b
diff --git a/mineru/backend/hybrid/hybrid_analyze.py b/mineru/backend/hybrid/hybrid_analyze.py
index 5ad1fd72..97cc5566 100644
--- a/mineru/backend/hybrid/hybrid_analyze.py
+++ b/mineru/backend/hybrid/hybrid_analyze.py
@@ -95,13 +95,23 @@ def _validate_hybrid_mode(mode: str) -> str:
return mode
-def _vlm_type_for_flash_layout_label(label: str | None) -> str | None:
- """将 pipeline layout 标签映射为 mineru-vl-utils 支持的 VLM 抽取类型。"""
+def _vlm_type_for_flash_layout_label(label: str | None, image_analysis: bool = True) -> str | None:
+ """将 pipeline layout 标签按 image_analysis 开关映射为 VLM 抽取类型。"""
if label in FLASH_LAYOUT_VISUAL_LABELS:
+ if not image_analysis and label == "chart":
+ return BlockType.CHART
return BlockType.IMAGE
return FLASH_LAYOUT_LABEL_TO_VLM_TYPE.get(label)
+def _apply_flash_visual_sub_type(block, label: str | None, image_analysis: bool):
+ """为不开启 image analysis 的视觉块补充下游需要透传的子类型。"""
+ if image_analysis:
+ return
+ if label == "seal":
+ block["sub_type"] = "seal"
+
+
def _is_hybrid_ocr_det_candidate(block):
"""判断 Hybrid 文本类块是否需要 OCR det 生成行级视觉信息。"""
return (block.get("type") or block.get("label")) in HYBRID_OCR_DET_TEXT_TYPES
@@ -369,12 +379,12 @@ def _normalize_flash_vlm_angle(angle):
return 0
-def _build_flash_vlm_layout_blocks(layout_dets, page_width, page_height):
+def _build_flash_vlm_layout_blocks(layout_dets, page_width, page_height, image_analysis=True):
"""用 pipeline layout 构造 VLM 外部 layout 输入,跳过 VLM 自身 layout 解析。"""
blocks = []
for layout_det in layout_dets or []:
label = layout_det.get("label")
- vlm_type = _vlm_type_for_flash_layout_label(label)
+ vlm_type = _vlm_type_for_flash_layout_label(label, image_analysis)
if vlm_type is None:
continue
bbox = _layout_det_bbox_to_unit(layout_det, page_width, page_height)
@@ -390,6 +400,7 @@ def _build_flash_vlm_layout_blocks(layout_dets, page_width, page_height):
except AssertionError as exc:
logger.warning(f"Skip invalid Hybrid flash VLM block: {layout_det}, error: {exc}")
continue
+ _apply_flash_visual_sub_type(block, label, image_analysis)
blocks.append(block)
return blocks
@@ -1063,6 +1074,7 @@ def doc_analyze(
page_layout_res,
pil_img.width,
pil_img.height,
+ image_analysis=image_analysis,
)
for page_layout_res, pil_img in zip(images_layout_res, images_pil_list)
]
@@ -1277,6 +1289,7 @@ async def aio_doc_analyze(
page_layout_res,
pil_img.width,
pil_img.height,
+ image_analysis=image_analysis,
)
for page_layout_res, pil_img in zip(images_layout_res, images_pil_list)
]