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: rename batch_radio to batch_ratio for consistency across modules
myhlolia7e43b22bd47
diff --git a/mineru/backend/hybrid/hybrid_analyze.py b/mineru/backend/hybrid/hybrid_analyze.pyindex 32d42333..1d416aaa 100644--- a/mineru/backend/hybrid/hybrid_analyze.py+++ b/mineru/backend/hybrid/hybrid_analyze.py@@ -63,7 +63,7 @@ def ocr_det(model_list,mfd_res,_ocr_enable,- batch_radio: int = 1,+ batch_ratio: int = 1,):def _set_temp_pixel_bbox(res, pixel_bbox):res["_normalized_bbox"] = list(res["bbox"])@@ -173,7 +173,7 @@ def ocr_det(batch_images.append(padded_img)# 批处理检测- det_batch_size = min(len(batch_images), batch_radio*OCR_DET_BASE_BATCH_SIZE)+ det_batch_size = min(len(batch_images), batch_ratio * OCR_DET_BASE_BATCH_SIZE)batch_results = hybrid_pipeline_model.ocr_model.text_detector.batch_predict(batch_images, det_batch_size)# 处理批处理结果@@ -282,7 +282,7 @@ def _process_ocr_and_formulas(language,inline_formula_enable,_ocr_enable,- batch_radio: int = 1,+ batch_ratio: int = 1,):"""处理OCR和公式识别"""@@ -306,14 +306,14 @@ def _process_ocr_and_formulas(# 使用layout模型提供行内公式检测框images_layout_res = hybrid_pipeline_model.layout_model.batch_predict(np_images,- batch_size=min(8, batch_radio * LAYOUT_BASE_BATCH_SIZE),+ batch_size=min(8, batch_ratio * LAYOUT_BASE_BATCH_SIZE),)images_mfd_res = _build_inline_formula_inputs(images_layout_res)# 公式识别inline_formula_list = hybrid_pipeline_model.mfr_model.batch_predict(images_mfd_res,np_images,- batch_size=batch_radio * MFR_BASE_BATCH_SIZE,+ batch_size=batch_ratio * MFR_BASE_BATCH_SIZE,interline_enable=True,)else:@@ -336,7 +336,7 @@ def _process_ocr_and_formulas(model_list,mfd_res,_ocr_enable,- batch_radio=batch_radio,+ batch_ratio=batch_ratio,)# 如果需要ocr则做ocr_rec@@ -612,7 +612,7 @@ def doc_analyze(language,inline_formula_enable,_ocr_enable,- batch_radio=batch_ratio,+ batch_ratio=batch_ratio,)model_list.extend(window_model_list)@@ -739,7 +739,7 @@ async def aio_doc_analyze(language,inline_formula_enable,_ocr_enable,- batch_radio=batch_ratio,+ batch_ratio=batch_ratio,)model_list.extend(window_model_list)diff --git a/mineru/backend/pipeline/para_split.py b/mineru/backend/pipeline/para_split.pyindex f38ccbfa..bc935272 100644--- a/mineru/backend/pipeline/para_split.py+++ b/mineru/backend/pipeline/para_split.py@@ -89,10 +89,10 @@ def __is_list_or_index_block(block):last_line = block['lines'][-1]if page_weight == 0:- block_weight_radio = 0+ block_weight_ratio = 0else:- block_weight_radio = block_weight / page_weight- # logger.info(f"block_weight_radio: {block_weight_radio}")+ block_weight_ratio = block_weight / page_weight+ # logger.info(f"block_weight_ratio: {block_weight_ratio}")# 如果首行左边不顶格而右边顶格,末行左边顶格而右边不顶格 (第一行可能可以右边不顶格)if (@@ -145,7 +145,7 @@ def __is_list_or_index_block(block):else:# 右侧不顶格情况下是否有一段距离,拍脑袋用0.3block宽度做阈值# block宽的阈值可以小些,block窄的阈值要大- if block_weight_radio >= 0.5:+ if block_weight_ratio >= 0.5:closed_area = 0.26 * block_weightelse:closed_area = 0.36 * block_weight@@ -203,7 +203,7 @@ def __is_list_or_index_block(block):left_close_num >= 2and (right_not_close_num >= 2 or line_end_flag or left_not_close_num >= 2)and not multiple_para_flag- # and block_weight_radio > 0.27+ # and block_weight_ratio > 0.27):# 处理一种特殊的没有缩进的list,所有行都贴左边,通过右边的空隙判断是否是item尾if left_close_num / len(block['lines']) > 0.8:diff --git a/mineru/utils/span_block_fix.py b/mineru/utils/span_block_fix.pyindex c4b7be9f..6eaa9bff 100644--- a/mineru/utils/span_block_fix.py+++ b/mineru/utils/span_block_fix.py@@ -6,7 +6,7 @@ from mineru.utils.ocr_utils import _is_overlaps_y_exceeds_threshold, _is_overlapVERTICAL_SPAN_HEIGHT_TO_WIDTH_RATIO_THRESHOLD = 2VERTICAL_SPAN_IN_BLOCK_THRESHOLD = 0.8-def fill_spans_in_blocks(blocks, spans, radio):+def fill_spans_in_blocks(blocks, spans, ratio):"""将allspans中的span按位置关系,放入blocks中."""block_with_spans = []for block in blocks:@@ -23,11 +23,11 @@ def fill_spans_in_blocks(blocks, spans, radio):block_dict['group_id'] = block[-1]block_spans = []for span in spans:- temp_radio = radio+ temp_ratio = ratiospan_bbox = span['bbox']if span['type'] in [ContentType.IMAGE, ContentType.TABLE]:- temp_radio = 0.9- if calculate_overlap_area_in_bbox1_area_ratio(span_bbox, block_bbox) > temp_radio and span_block_type_compatible(span['type'], block_type):+ temp_ratio = 0.9+ if calculate_overlap_area_in_bbox1_area_ratio(span_bbox, block_bbox) > temp_ratio and span_block_type_compatible(span['type'], block_type):block_spans.append(span)block_dict['spans'] = block_spans@@ -241,4 +241,4 @@ def fix_interline_block(block):sort_block_lines = line_sort_spans_by_left_to_right(block_lines)block['lines'] = sort_block_linesdel block['spans']- return block\ No newline at end of file+ return blockdiff --git a/mineru/utils/span_pre_proc.py b/mineru/utils/span_pre_proc.pyindex 159b08f0..cb8defbc 100644--- a/mineru/utils/span_pre_proc.py+++ b/mineru/utils/span_pre_proc.py@@ -249,8 +249,8 @@ def fill_char_in_spans(spans, all_chars, median_span_height):LINE_STOP_FLAG = ('.', '!', '?', '。', '!', '?', ')', ')', '"', '”', ':', ':', ';', ';', ']', '】', '}', '}', '>', '》', '、', ',', ',', '-', '—', '–',)LINE_START_FLAG = ('(', '(', '"', '“', '【', '{', '《', '<', '「', '『', '【', '[',)-Span_Height_Radio = 0.33 # 字符的中轴和span的中轴高度差不能超过1/3span高度-def calculate_char_in_span(char_bbox, span_bbox, char, span_height_radio=Span_Height_Radio):+Span_Height_Ratio = 0.33 # 字符的中轴和span的中轴高度差不能超过1/3span高度+def calculate_char_in_span(char_bbox, span_bbox, char, span_height_ratio=Span_Height_Ratio):char_center_x = (char_bbox[0] + char_bbox[2]) / 2char_center_y = (char_bbox[1] + char_bbox[3]) / 2span_center_y = (span_bbox[1] + span_bbox[3]) / 2@@ -259,7 +259,7 @@ def calculate_char_in_span(char_bbox, span_bbox, char, span_height_radio=Span_Heif (span_bbox[0] < char_center_x < span_bbox[2]and span_bbox[1] < char_center_y < span_bbox[3]- and abs(char_center_y - span_center_y) < span_height * span_height_radio # 字符的中轴和span的中轴高度差不能超过Span_Height_Radio+ and abs(char_center_y - span_center_y) < span_height * span_height_ratio # 字符的中轴和span的中轴高度差不能超过Span_Height_Ratio):return Trueelse:@@ -270,7 +270,7 @@ def calculate_char_in_span(char_bbox, span_bbox, char, span_height_radio=Span_He(span_bbox[2] - span_height) < char_bbox[0] < span_bbox[2]and char_center_x > span_bbox[0]and span_bbox[1] < char_center_y < span_bbox[3]- and abs(char_center_y - span_center_y) < span_height * span_height_radio+ and abs(char_center_y - span_center_y) < span_height * span_height_ratio):return Trueelif char in LINE_START_FLAG:@@ -278,7 +278,7 @@ def calculate_char_in_span(char_bbox, span_bbox, char, span_height_radio=Span_Hespan_bbox[0] < char_bbox[2] < (span_bbox[0] + span_height)and char_center_x < span_bbox[2]and span_bbox[1] < char_center_y < span_bbox[3]- and abs(char_center_y - span_center_y) < span_height * span_height_radio+ and abs(char_center_y - span_center_y) < span_height * span_height_ratio):return Trueelse:@@ -339,4 +339,4 @@ def calculate_contrast(img, img_mode) -> float:# 对比度定义为标准差除以平均值(加上小常数避免除零错误)contrast = std_dev / (mean_value + 1e-6)# logger.debug(f"contrast: {contrast}")- return round(contrast, 2)\ No newline at end of file+ return round(contrast, 2)