Skip to content

Commit 709a1d2

Browse files
committed
优化PP-DocLayoutV2集成
1 parent 99b4e9f commit 709a1d2

File tree

16 files changed

+477
-157
lines changed

16 files changed

+477
-157
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
- **版面识别**
2727
- 模型使用 `PP-DocLayout` 系列 ONNX 模型(v2、plus-L、L、M、S)
28-
- **PP-DocLayoutV2**PaddleOCR-VL使用的版面模型,自带阅读顺序
29-
- **PP-DocLayout_plus-L**:效果好运行稳定,默认使用
28+
- **PP-DocLayoutV2**:自带阅读顺序,效果最好,默认使用
29+
- **PP-DocLayout_plus-L**:效果好运行稳定
3030
- **PP-DocLayout-L**:速度快,效果也不错
3131
- **PP-DocLayout-S**:速度极快,存在部分漏检
3232

@@ -56,7 +56,7 @@
5656

5757
### 1. OmniDocBench
5858

59-
以下是RapidDoc在 OmniDocBench 上的评估结果。Pipeline 模型使用 PP-DocLayout_plus-L、PP-OCRv5-mobile、PP-FormulaNet_plus-M、UNET_SLANET_PLUS。
59+
以下是RapidDoc在 OmniDocBench 上的评估结果。Pipeline 模型使用 PP-DocLayoutV2、PP-OCRv5-mobile、PP-FormulaNet_plus-M、UNET_SLANET_PLUS。
6060
<table style="width:100%; border-collapse: collapse;">
6161
<caption>Comprehensive evaluation of document parsing on OmniDocBench (v1.5)</caption>
6262
<thead>
@@ -295,6 +295,16 @@
295295
</tr>
296296
<tr>
297297
<td rowspan="4"><strong>Pipeline</strong><br><strong>Tools</strong></td>
298+
<td><strong>RapidDoc</strong></td>
299+
<td>-</td>
300+
<td>87.81</td>
301+
<td>0.065</td>
302+
<td>89.348</td>
303+
<td>80.59</td>
304+
<td>87.90</td>
305+
<td>0.053</td>
306+
</tr>
307+
<tr>
298308
<td>PP-StructureV3</td>
299309
<td>-</td>
300310
<td>86.73</td>
@@ -304,16 +314,6 @@
304314
<td>89.48</td>
305315
<td>0.073</td>
306316
</tr>
307-
<tr>
308-
<td><strong>RapidDoc</strong></td>
309-
<td>-</td>
310-
<td>85.25</td>
311-
<td>0.085</td>
312-
<td>85.19</td>
313-
<td>79.07</td>
314-
<td>86.35</td>
315-
<td>0.114</td>
316-
</tr>
317317
<tr>
318318
<td>Mineru2-pipeline</td>
319319
<td>-</td>

demo.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ def do_parse(
4141
f_dump_model_output=True, # Whether to dump model output files
4242
f_dump_orig_pdf=True, # Whether to dump original PDF files
4343
f_dump_content_list=True, # Whether to dump content list files
44-
f_dump_md_html=True, # Whether to convert markdown to HTML
45-
f_dump_md_docx=True, # Whether to convert markdown to docx (via Pandoc)
44+
f_dump_md_html=False, # Whether to convert markdown to HTML
45+
f_dump_md_docx=False, # Whether to convert markdown to docx (via Pandoc)
4646
f_make_md_mode=MakeMode.MM_MD, # The mode for making markdown content, default is MM_MD
4747
start_page_id=0, # Start page ID for parsing, default is 0
4848
end_page_id=None, # End page ID for parsing, default is None (parse all pages until the end of the document)
4949
):
5050
layout_config = {
51-
# "model_type": LayoutModelType.PP_DOCLAYOUT_PLUS_L,
51+
# "model_type": LayoutModelType.PP_DOCLAYOUTV2,
5252
# "conf_thresh": 0.4,
5353
# "batch_num": 1,
54-
# "model_dir_or_path": r"C:\ocr\models\ppmodel\layout\PP-DocLayout_plus-L\pp_doclayout_plus_l.onnx",
54+
# "model_dir_or_path": r"C:\ocr\models\ppmodel\layout\PP-DocLayoutV2\pp_doclayoutv2.onnx",
55+
# "markdown_ignore_labels": ["number", "footnote", "header", "header_image", "footer", "footer_image", "aside_text",]
5556
}
5657

5758
ocr_config = {
@@ -85,7 +86,7 @@ def do_parse(
8586

8687
table_config = {
8788
# "force_ocr": False, # 表格文字,是否强制使用ocr,默认 False 根据 parse_method 来判断是否需要ocr还是从pdf中直接提取文本
88-
# 注:文字版pdf可以使用pypdfium2提取到表格内图片,扫描版或图片需要使用PP_DOCLAYOUT_PLUS_L版面识别模型,才能识别到表格内的图片
89+
# 注:文字版pdf可以使用pypdfium2提取到表格内图片,扫描版或图片需要使用PP_DOCLAYOUT_PLUS_L/PP_DOCLAYOUTV2版面识别模型,才能识别到表格内的图片
8990
# "skip_text_in_image": True, # 是否跳过表格里图片中的文字(如表格单元格中嵌入的图片、图标、扫描底图等)
9091
# "use_img2table": False, # 是否优先使用img2table库提取表格,需要手动安装(pip install img2table),基于opencv识别准确度不如使用模型,但是速度很快,默认关闭
9192

demo/RapidDoc_end2end.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from rapid_doc.backend.pipeline.pipeline_analyze import doc_analyze as pipeline_doc_analyze
1717
from rapid_doc.backend.pipeline.pipeline_middle_json_mkcontent import union_make as pipeline_union_make
1818
from rapid_doc.backend.pipeline.model_json_to_middle_json import result_to_middle_json as pipeline_result_to_middle_json
19+
from rapid_doc.model.layout.rapid_layout_self import ModelType as LayoutModelType
1920

2021
def do_parse(
2122
output_dir,
@@ -30,6 +31,7 @@ def do_parse(
3031
end_page_id=None,
3132
):
3233
layout_config = {
34+
"model_type": LayoutModelType.PP_DOCLAYOUTV2,
3335
}
3436

3537
ocr_config = {
@@ -112,13 +114,14 @@ def parse_doc(
112114

113115

114116
if __name__ == '__main__':
115-
files_dir = r"/root/hzkitty/OmniDocBenchFiles/images"
116-
output_dir = r"/root/hzkitty/OmniDocBenchFiles/layout_plus_l-ocr_mobile-image"
117+
files_dir = r"/root/hzkitty/OmniDocBenchFiles/pdfs"
118+
output_dir = r"/root/hzkitty/OmniDocBenchFiles/layout_v2-ocr_mobile-pdf"
117119

118-
# files_dir = r"D:\Download\OmniDocBench\images"
119-
# output_dir = r"D:\Download\OmniDocBench\layout_plus_l-ocr_mobile-image"
120+
# files_dir = r"D:\Download\OmniDocBench\pdfs"
121+
# output_dir = r"D:\Download\OmniDocBench\layout_v2-ocr_mobile-pdf"
120122

121-
suffixes = [".pdf", ".png", ".jpg", ".jpeg"]
123+
# suffixes = [".pdf", ".png", ".jpg", ".jpeg"]
124+
suffixes = [".pdf"]
122125
batch_size = 100
123126

124127
doc_path_list = []

demo/demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def do_parse(
4545

4646

4747
layout_config = {
48-
"model_type": LayoutModelType.PP_DOCLAYOUT_PLUS_L,
48+
"model_type": LayoutModelType.PP_DOCLAYOUTV2,
4949
# "conf_thresh": 0.4,
5050
# "batch_num": 1,
51-
# "model_dir_or_path": "C:\ocr\models\ppmodel\layout\PP-DocLayout-L\pp_doclayout_l.onnx"
51+
# "model_dir_or_path": "C:\ocr\models\ppmodel\layout\PP-DocLayoutV2\pp_doclayoutv2.onnx"
5252
}
5353

5454
ocr_config = {
@@ -82,7 +82,7 @@ def do_parse(
8282

8383
table_config = {
8484
# "force_ocr": False, # 表格文字,是否强制使用ocr,默认 False 根据 parse_method 来判断是否需要ocr还是从pdf中直接提取文本
85-
# 注:文字版pdf可以使用pypdfium2提取到表格内图片,扫描版或图片需要使用PP_DOCLAYOUT_PLUS_L版面识别模型,才能识别到表格内的图片
85+
# 注:文字版pdf可以使用pypdfium2提取到表格内图片,扫描版或图片需要使用PP_DOCLAYOUT_PLUS_L/PP_DOCLAYOUTV2版面识别模型,才能识别到表格内的图片
8686
# "skip_text_in_image": True, # 是否跳过表格里图片中的文字(如表格单元格中嵌入的图片、图标、扫描底图等)
8787
# "use_img2table": False, # 是否优先使用img2table库提取表格,需要手动安装(pip install img2table),基于opencv识别准确度不如使用模型,但是速度很快,默认关闭
8888

docker/README_API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ curl --location --request POST 'http://localhost:8888/file_parse' \
103103
--form 'return_content_list=true' \
104104
--form 'return_images=true' \
105105
--form 'clear_output_file=false' \
106-
--form 'layout_config="{\"model_type\": \"LayoutModelType.PP_DOCLAYOUT_PLUS_L\"}"'
106+
--form 'layout_config="{\"model_type\": \"LayoutModelType.PP_DOCLAYOUTV2\"}"'
107107

108108
# 多文件批量处理
109109
curl -X POST "http://localhost:8888/file_parse" \

docs/analyze_param.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ os.environ['MINERU_DEVICE_MODE'] = "cuda:1"
4646

4747
#### 2、layout_config 版面解析参数说明如下:
4848

49-
| 参数名 | 说明 | 默认值 | 备注 |
50-
| :-------: |:-----:|:-------------------:|:--:|
51-
| model_type | 模型 | PP_DOCLAYOUT_PLUS_L | |
52-
| conf_thresh | 阈值 | 0.5(_S为0.2) | |
53-
| batch_num | 批处理大小 | 1 | |
54-
| model_dir_or_path | 模型路径 | None | |
49+
| 参数名 | 说明 | 默认值 | 备注 |
50+
| :-------: |:-------:|:-------------------:|:--:|
51+
| model_type | 模型 | PP_DOCLAYOUTV2 | |
52+
| conf_thresh | 阈值 | 0.5(_S为0.2) | |
53+
| batch_num | 批处理大小 | 1 | |
54+
| model_dir_or_path | 模型路径 | None | |
55+
| markdown_ignore_labels | 忽略的版面类型 | ["number","footnote","header","header_image","footer","footer_image","aside_text",] | |
5556
示例:
5657

5758
```python
@@ -151,7 +152,7 @@ from rapid_doc.model.table.rapid_table_self import ModelType as TableModelType,
151152

152153
table_config = {
153154
# "force_ocr": False, # 表格文字,是否强制使用ocr,默认 False 根据 parse_method 来判断是否需要ocr还是从pdf中直接提取文本
154-
# 注:文字版pdf可以使用pypdfium2提取到表格内图片,扫描版或图片需要使用PP_DOCLAYOUT_PLUS_L版面识别模型,才能识别到表格内的图片
155+
# 注:文字版pdf可以使用pypdfium2提取到表格内图片,扫描版或图片需要使用PP_DOCLAYOUT_PLUS_L/PP_DOCLAYOUTV2版面识别模型,才能识别到表格内的图片
155156
# "skip_text_in_image": True, # 是否跳过表格里图片中的文字(如表格单元格中嵌入的图片、图标、扫描底图等)
156157
# "use_img2table": False, # 是否优先使用img2table库提取表格,需要手动安装(pip install img2table),基于opencv识别准确度不如使用模型,但是速度很快,默认关闭
157158

rapid_doc/backend/pipeline/pipeline_magic_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ def __get_blocks_by_type(
392392
if category_id == category_type:
393393
block = {
394394
'bbox': bbox,
395+
'original_label': item.get('original_label'),
396+
'original_order': item.get('original_order'),
395397
'score': item.get('score'),
396398
}
397399
for col in extra_col:

0 commit comments

Comments
 (0)