对比两个OCR识别结果:
从 bank_statement_yusys_v2/2023年度报告母公司_page_003.json 中发现的错误:
| 正确文本 | 识别结果 | 匹配分数 | 问题 |
|---|---|---|---|
| 合同资产 | 货资产 | 80.0% | 检测框不完整 |
| 其他应付款 | 税款 | 66.67% | 检测框错误 |
| 长期待摊费用 | 效用 | 66.67% | 检测框错误 |
| 其他非流动资产 | 非其非产动产 | 61.54% | 检测框合并错误 |
| 资本公积 | 资公存股 | 66.67% | 检测框合并错误 |
| 参数 | PPStructureV3 | MinerU默认 | 影响 |
|---|---|---|---|
box_thresh |
0.6 | 0.3 | 阈值过低导致检测到大量噪声框 |
unclip_ratio |
1.5 | 1.8 | 扩展比例过高,框不够精确 |
thresh |
0.3 | 0.3 | 相同 |
问题:
box_thresh=0.3 太低,会检测到很多低置信度的噪声框| 特性 | PPStructureV3 | MinerU | 影响 |
|---|---|---|---|
| 框合并 | 无(或更保守) | enable_merge_det_boxes=True |
可能错误合并相邻文本块 |
问题:
enable_merge_det_boxes=True 会合并相邻的检测框| 参数 | PPStructureV3 | MinerU | 影响 |
|---|---|---|---|
score_thresh |
0.0 | 0.5 | 丢弃低置信度结果 |
问题:
drop_score=0.5 会丢弃置信度 < 0.5 的识别结果score_thresh=0.0,保留所有结果| 特性 | PPStructureV3 | MinerU | 影响 |
|---|---|---|---|
| 文本行方向识别 | ✅ use_textline_orientation: True |
❌ 无 | 倾斜文本识别错误 |
问题:
| 组件 | PPStructureV3 | MinerU | 影响 |
|---|---|---|---|
| 检测模型 | PP-OCRv5_server_det | ch/ch_lite | 可能使用较旧版本 |
| 识别模型 | PP-OCRv5_server_rec | ch/ch_lite | 可能使用较旧版本 |
问题:
修改 MinerUOCRRecognizer 的初始化参数,使其更接近 PPStructureV3:
# 在 mineru_adapter.py 中修改
self.ocr_model = self.atom_model_manager.get_atom_model(
atom_model_name=AtomicModel.OCR,
det_db_box_thresh=0.6, # 从 0.3 提高到 0.6
lang=self.config.get('language', 'ch'),
det_db_unclip_ratio=1.5, # 从 1.8 降低到 1.5
enable_merge_det_boxes=False, # 从 True 改为 False(表格场景)
)
优点:
缺点:
enable_merge_det_boxes=True修改 drop_score 参数,保留更多识别结果:
# 需要修改 PytorchPaddleOCR 的初始化
kwargs['drop_score'] = 0.3 # 从默认 0.5 降低到 0.3
优点:
缺点:
根据文档类型(表格/文本)和PDF类型(扫描件/数字PDF)动态调整参数:
def get_ocr_config(pdf_type: str, has_tables: bool) -> Dict[str, Any]:
"""根据场景返回OCR配置"""
if has_tables:
# 表格场景:更严格的检测,不合并框
return {
'det_db_box_thresh': 0.6,
'det_db_unclip_ratio': 1.5,
'enable_merge_det_boxes': False,
'drop_score': 0.3,
}
elif pdf_type == 'txt':
# 数字PDF:可以合并框,提高检测阈值
return {
'det_db_box_thresh': 0.5,
'det_db_unclip_ratio': 1.6,
'enable_merge_det_boxes': True,
'drop_score': 0.3,
}
else:
# 扫描件:平衡检测和合并
return {
'det_db_box_thresh': 0.4,
'det_db_unclip_ratio': 1.6,
'enable_merge_det_boxes': True,
'drop_score': 0.3,
}
优点:
缺点:
参考 PPStructureV3,添加文本行方向识别模块:
优点:
缺点:
调整检测参数:
det_db_box_thresh: 0.3 → 0.6det_db_unclip_ratio: 1.8 → 1.5enable_merge_det_boxes: True → False(表格场景)降低识别阈值:
drop_score: 0.5 → 0.3ocr:
det_db_box_thresh: 0.6 # 提高检测阈值
det_db_unclip_ratio: 1.5 # 降低扩展比例
enable_merge_det_boxes: false # 不合并框
drop_score: 0.3 # 降低识别阈值
ocr:
det_db_box_thresh: 0.4 # 中等检测阈值
det_db_unclip_ratio: 1.6 # 中等扩展比例
enable_merge_det_boxes: true # 允许合并
drop_score: 0.3 # 降低识别阈值
models/adapters/mineru_adapter.py:
MinerUOCRRecognizer.__init__() - 修改初始化参数core/pipeline_manager_v2.py:
_process_single_page() - 检测是否有表格配置文件:
实施阶段1改进后:
参数调优:
性能影响:
box_thresh 可能略微降低召回率向后兼容: