|
|
@@ -0,0 +1,2075 @@
|
|
|
+---
|
|
|
+comments: true
|
|
|
+---
|
|
|
+
|
|
|
+# 文档场景信息抽取v4产线使用教程
|
|
|
+
|
|
|
+## 1. 文档场景信息抽取v4产线介绍
|
|
|
+文档场景信息抽取v4(PP-ChatOCRv4)是飞桨特色的文档和图像智能分析解决方案,结合了 LLM、MLLM 和 OCR 技术,一站式解决版面分析、生僻字、多页 pdf、表格、印章识别等常见的复杂文档信息抽取难点问题,结合文心大模型将海量数据和知识相融合,准确率高且应用广泛。本产线同时提供了灵活的服务化部署方式,支持在多种硬件上部署。不仅如此,本产线也提供了二次开发的能力,您可以基于本产线在您自己的数据集上训练调优,训练后的模型也可以无缝集成。
|
|
|
+
|
|
|
+<img src="https://github.com/user-attachments/assets/0870cdec-1909-4247-9004-d9efb4ab9635">
|
|
|
+
|
|
|
+文档场景信息抽取v4产线中包含<b>版面区域检测模块</b>、<b>表格结构识别模块</b>、<b>表格分类模块</b>、<b>表格单元格定位模块</b>、<b>文本检测模块</b>、<b>文本识别模块</b>、<b>印章文本检测模块</b>、<b>文本图像矫正模块</b>、<b>文档图像方向分类模块</b>。其中相关的模型是以子产线的方式集成,您可以通过[产线配置](../../../../paddlex/configs/pipelines/PP-ChatOCRv4-doc.yaml)来查看不同模块的模型配置。
|
|
|
+
|
|
|
+<b>如您更考虑模型精度,请选择精度较高的模型,如您更考虑模型推理速度,请选择推理速度较快的模型,如您更考虑模型存储大小,请选择存储大小较小的模型</b>。其中部分模型的 benchmark 如下:
|
|
|
+
|
|
|
+<details><summary> 👉模型列表详情</summary>
|
|
|
+
|
|
|
+<p><b>版面区域检测模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>mAP(0.5)(%)</th>
|
|
|
+<th>GPU推理耗时(ms)</th>
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小(M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td>PicoDet_layout_1x</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PicoDet_layout_1x_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PicoDet_layout_1x_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>86.8</td>
|
|
|
+<td>13.0</td>
|
|
|
+<td>91.3</td>
|
|
|
+<td>7.4</td>
|
|
|
+<td>基于PicoDet-1x在PubLayNet数据集训练的高效率版面区域定位模型,可定位包含文字、标题、表格、图片以及列表这5类区域</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PicoDet_layout_1x_table</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PicoDet_layout_1x_table_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PicoDet_layout_1x_table_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>95.7</td>
|
|
|
+<td>12.623</td>
|
|
|
+<td>90.8934</td>
|
|
|
+<td>7.4 M</td>
|
|
|
+<td>基于PicoDet-1x在自建数据集训练的高效率版面区域定位模型,可定位包含表格这1类区域</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PicoDet-S_layout_3cls</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PicoDet-S_layout_3cls_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PicoDet-S_layout_3cls_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>87.1</td>
|
|
|
+<td>13.5</td>
|
|
|
+<td>45.8</td>
|
|
|
+<td>4.8</td>
|
|
|
+<td>基于PicoDet-S轻量模型在中英文论文、杂志和研报等场景上自建数据集训练的高效率版面区域定位模型,包含3个类别:表格,图像和印章</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PicoDet-S_layout_17cls</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PicoDet-S_layout_17cls_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PicoDet-S_layout_17cls_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>70.3</td>
|
|
|
+<td>13.6</td>
|
|
|
+<td>46.2</td>
|
|
|
+<td>4.8</td>
|
|
|
+<td>基于PicoDet-S轻量模型在中英文论文、杂志和研报等场景上自建数据集训练的高效率版面区域定位模型,包含17个版面常见类别,分别是:段落标题、图片、文本、数字、摘要、内容、图表标题、公式、表格、表格标题、参考文献、文档标题、脚注、页眉、算法、页脚、印章</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PicoDet-L_layout_3cls</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PicoDet-L_layout_3cls_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PicoDet-L_layout_3cls_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>89.3</td>
|
|
|
+<td>15.7</td>
|
|
|
+<td>159.8</td>
|
|
|
+<td>22.6</td>
|
|
|
+<td>基于PicoDet-L在中英文论文、杂志和研报等场景上自建数据集训练的高效率版面区域定位模型,包含3个类别:表格,图像和印章</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PicoDet-L_layout_17cls</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PicoDet-L_layout_17cls_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PicoDet-L_layout_17cls_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>79.9</td>
|
|
|
+<td>17.2</td>
|
|
|
+<td>160.2</td>
|
|
|
+<td>22.6</td>
|
|
|
+<td>基于PicoDet-L在中英文论文、杂志和研报等场景上自建数据集训练的高效率版面区域定位模型,包含17个版面常见类别,分别是:段落标题、图片、文本、数字、摘要、内容、图表标题、公式、表格、表格标题、参考文献、文档标题、脚注、页眉、算法、页脚、印章</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>RT-DETR-H_layout_3cls</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/RT-DETR-H_layout_3cls_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/RT-DETR-H_layout_3cls_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>95.9</td>
|
|
|
+<td>114.6</td>
|
|
|
+<td>3832.6</td>
|
|
|
+<td>470.1</td>
|
|
|
+<td>基于RT-DETR-H在中英文论文、杂志和研报等场景上自建数据集训练的高精度版面区域定位模型,包含3个类别:表格,图像和印章</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>RT-DETR-H_layout_17cls</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/RT-DETR-H_layout_17cls_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/RT-DETR-H_layout_17cls_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>92.6</td>
|
|
|
+<td>115.1</td>
|
|
|
+<td>3827.2</td>
|
|
|
+<td>470.2</td>
|
|
|
+<td>基于RT-DETR-H在中英文论文、杂志和研报等场景上自建数据集训练的高精度版面区域定位模型,包含17个版面常见类别,分别是:段落标题、图片、文本、数字、摘要、内容、图表标题、公式、表格、表格标题、参考文献、文档标题、脚注、页眉、算法、页脚、印章</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><b>注:以上精度指标的评估集是 PaddleOCR 自建的版面区域分析数据集,包含中英文论文、杂志和研报等常见的 1w 张文档类型图片。GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为 8,精度类型为 FP32。</b></p>
|
|
|
+
|
|
|
+<p><b>表格结构识别模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>精度(%)</th>
|
|
|
+<th>GPU推理耗时 (ms)</th>
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小 (M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>SLANet</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/SLANet_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/SLANet_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>59.52</td>
|
|
|
+<td>522.536</td>
|
|
|
+<td>1845.37</td>
|
|
|
+<td>6.9 M</td>
|
|
|
+<td rowspan="1">SLANet 是百度飞桨视觉团队自研的表格结构识别模型。该模型通过采用 CPU 友好型轻量级骨干网络 PP-LCNet、高低层特征融合模块 CSP-PAN、结构与位置信息对齐的特征解码模块 SLA Head,大幅提升了表格结构识别的精度和推理速度。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>SLANet_plus</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/SLANet_plus_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/SLANet_plus_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>63.69</td>
|
|
|
+<td>522.536</td>
|
|
|
+<td>1845.37</td>
|
|
|
+<td>6.9 M</td>
|
|
|
+<td rowspan="1">SLANet_plus 是百度飞桨视觉团队自研的表格结构识别模型 SLANet 的增强版。相较于 SLANet,SLANet_plus 对无线表、复杂表格的识别能力得到了大幅提升,并降低了模型对表格定位准确性的敏感度,即使表格定位出现偏移,也能够较准确地进行识别。
|
|
|
+</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>SLANeXt_wired</td>
|
|
|
+<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/SLANeXt_wired_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/SLANeXt_wired_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td rowspan="2">69.65</td>
|
|
|
+<td rowspan="2">--</td>
|
|
|
+<td rowspan="2">--</td>
|
|
|
+<td rowspan="2">--</td>
|
|
|
+<td rowspan="2">SLANeXt 系列是百度飞桨视觉团队自研的新一代表格结构识别模型。相较于 SLANet 和 SLANet_plus,SLANeXt 专注于对表格结构进行识别,并且对有线表格(wired)和无线表格(wireless)的识别分别训练了专用的权重,对各类型表格的识别能力都得到了明显提高,特别是对有线表格的识别能力得到了大幅提升。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>SLANeXt_wireless</td>
|
|
|
+<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/SLANeXt_wireless_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/SLANeXt_wireless_pretrained.pdparams">训练模型</a></td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+<p><b>注:以上精度指标测量PaddleX 内部自建英文表格识别数据集。所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
+
|
|
|
+<p><b>表格分类模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>Top1 Acc(%)</th>
|
|
|
+<th>GPU推理耗时 (ms)</th>
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小 (M)</th>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PP-LCNet_x1_0_table_cls</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/CLIP_vit_base_patch16_224_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-LCNet_x1_0_table_cls_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>--</td>
|
|
|
+<td>--</td>
|
|
|
+<td>--</td>
|
|
|
+<td>--</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+<p><b>注:以上精度指标测量自 PaddleX 内部自建表格分类数据集。所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
+
|
|
|
+<p><b>表格单元格检测模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>mAP(%)</th>
|
|
|
+<th>GPU推理耗时 (ms)</th>
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小 (M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>RT-DETR-L_wired_table_cell_det</td>
|
|
|
+<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/RT-DETR-L_wired_table_cell_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/RT-DETR-L_wired_table_cell_det_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td rowspan="2">--</td>
|
|
|
+<td rowspan="2">--</td>
|
|
|
+<td rowspan="2">--</td>
|
|
|
+<td rowspan="2">--</td>
|
|
|
+<td rowspan="2">RT-DETR 是第一个实时的端到端目标检测模型。百度飞桨视觉团队基于 RT-DETR-L 作为基础模型,在自建表格单元格检测数据集上完成预训练,实现了对有线表格、无线表格均有较好性能的表格单元格检测。
|
|
|
+</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>RT-DETR-L_wireless_table_cell_det</td>
|
|
|
+<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/RT-DETR-L_wireless_table_cell_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/RT-DETR-L_wired_table_cell_det_pretrained.pdparams">训练模型</a></td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+<p><b>注:以上精度指标测量自 PaddleX 内部自建表格单元格检测数据集。所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
+
|
|
|
+<p><b>文本检测模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>检测Hmean(%)</th>
|
|
|
+<th>GPU推理耗时(ms)</th>
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小(M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td>PP-OCRv4_server_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-OCRv4_server_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_server_det_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>82.69</td>
|
|
|
+<td>83.3501</td>
|
|
|
+<td>2434.01</td>
|
|
|
+<td>109</td>
|
|
|
+<td>PP-OCRv4 的服务端文本检测模型,精度更高,适合在性能较好的服务器上部署</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PP-OCRv4_mobile_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-OCRv4_mobile_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_mobile_det_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>77.79</td>
|
|
|
+<td>10.6923</td>
|
|
|
+<td>120.177</td>
|
|
|
+<td>4.7</td>
|
|
|
+<td>PP-OCRv4 的移动端文本检测模型,效率更高,适合在端侧设备部署</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><b>注:以上精度指标的评估集是 PaddleOCR 自建的中文数据集,覆盖街景、网图、文档、手写多个场景,其中检测包含 500 张图片。以上所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
+
|
|
|
+<p><b>文本识别模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>识别 Avg Accuracy(%)</th>
|
|
|
+<th>GPU推理耗时(ms)</th>
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小(M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PP-OCRv4_mobile_rec</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-OCRv4_mobile_rec_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_mobile_rec_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>78.20</td>
|
|
|
+<td>7.95018</td>
|
|
|
+<td>46.7868</td>
|
|
|
+<td>10.6 M</td>
|
|
|
+<td rowspan="2">PP-OCRv4是百度飞桨视觉团队自研的文本识别模型PP-OCRv3的下一个版本,通过引入数据增强方案、GTC-NRTR指导分支等策略,在模型推理速度不变的情况下,进一步提升了文本识别精度。该模型提供了服务端(server)和移动端(mobile)两个不同版本,来满足不同场景下的工业需求。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PP-OCRv4_server_rec </td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-OCRv4_server_rec_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_server_rec_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>79.20</td>
|
|
|
+<td>7.19439</td>
|
|
|
+<td>140.179</td>
|
|
|
+<td>71.2 M</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+
|
|
|
+<p><b>注:以上精度指标的评估集是 PaddleOCR 自建的中文数据集,覆盖街景、网图、文档、手写多个场景,其中文本识别包含 1.1w 张图片。所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
+<table>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>识别 Avg Accuracy(%)</th>
|
|
|
+<th>GPU推理耗时(ms)</th>
|
|
|
+<th>CPU推理耗时(ms)</th>
|
|
|
+<th>模型存储大小(M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>ch_SVTRv2_rec</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/ch_SVTRv2_rec_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/ch_SVTRv2_rec_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>68.81</td>
|
|
|
+<td>8.36801</td>
|
|
|
+<td>165.706</td>
|
|
|
+<td>73.9 M</td>
|
|
|
+<td rowspan="1">
|
|
|
+SVTRv2 是一种由复旦大学视觉与学习实验室(FVL)的OpenOCR团队研发的服务端文本识别模型,其在PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务中荣获一等奖,A榜端到端识别精度相比PP-OCRv4提升6%。
|
|
|
+</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+
|
|
|
+<p><b>注:以上精度指标的评估集是 <a href="https://aistudio.baidu.com/competition/detail/1131/0/introduction">PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务</a>A榜。 所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
+<table>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>识别 Avg Accuracy(%)</th>
|
|
|
+<th>GPU推理耗时(ms)</th>
|
|
|
+<th>CPU推理耗时(ms)</th>
|
|
|
+<th>模型存储大小(M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>ch_RepSVTR_rec</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/ch_RepSVTR_rec_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/ch_RepSVTR_rec_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>65.07</td>
|
|
|
+<td>10.5047</td>
|
|
|
+<td>51.5647</td>
|
|
|
+<td>22.1 M</td>
|
|
|
+<td rowspan="1"> RepSVTR 文本识别模型是一种基于SVTRv2 的移动端文本识别模型,其在PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务中荣获一等奖,B榜端到端识别精度相比PP-OCRv4提升2.5%,推理速度持平。</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+
|
|
|
+<p><b>注:以上精度指标的评估集是 <a href="https://aistudio.baidu.com/competition/detail/1131/0/introduction">PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务</a>B榜。 所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
+
|
|
|
+<p><b>印章文本检测模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>检测Hmean(%)</th>
|
|
|
+<th>GPU推理耗时(ms)</th>
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小(M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td>PP-OCRv4_server_seal_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-OCRv4_server_seal_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_server_seal_det_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>98.21</td>
|
|
|
+<td>84.341</td>
|
|
|
+<td>2425.06</td>
|
|
|
+<td>109</td>
|
|
|
+<td>PP-OCRv4的服务端印章文本检测模型,精度更高,适合在较好的服务器上部署</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td>PP-OCRv4_mobile_seal_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-OCRv4_mobile_seal_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_mobile_seal_det_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>96.47</td>
|
|
|
+<td>10.5878</td>
|
|
|
+<td>131.813</td>
|
|
|
+<td>4.6</td>
|
|
|
+<td>PP-OCRv4的移动端印章文本检测模型,效率更高,适合在端侧部署</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><b>注:以上精度指标的评估集是自建的数据集,包含500张圆形印章图像。GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为 8,精度类型为 FP32。</b></p>
|
|
|
+
|
|
|
+<p><b>文本图像矫正模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>MS-SSIM (%)</th>
|
|
|
+<th>模型存储大小(M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td>UVDoc</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/UVDoc_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/UVDoc_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>54.40</td>
|
|
|
+<td>30.3 M</td>
|
|
|
+<td>高精度文本图像矫正模型</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><b>模型的精度指标测量自 <a href="https://www3.cs.stonybrook.edu/~cvl/docunet.html">DocUNet benchmark</a>。</b></p>
|
|
|
+
|
|
|
+<p><b>文档图像方向分类模块模型:</b></p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>模型</th><th>模型下载链接</th>
|
|
|
+<th>Top-1 Acc(%)</th>
|
|
|
+<th>GPU推理耗时(ms)</th>
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
+<th>模型存储大小(M)</th>
|
|
|
+<th>介绍</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td>PP-LCNet_x1_0_doc_ori</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0rc0/PP-LCNet_x1_0_doc_ori_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-LCNet_x1_0_doc_ori_pretrained.pdparams">训练模型</a></td>
|
|
|
+<td>99.06</td>
|
|
|
+<td>3.84845</td>
|
|
|
+<td>9.23735</td>
|
|
|
+<td>7</td>
|
|
|
+<td>基于PP-LCNet_x1_0的文档图像分类模型,含有四个类别,即0度,90度,180度,270度</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><b>注:以上精度指标的评估集是自建的数据集,覆盖证件和文档等多个场景,包含 1000 张图片。GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为 8,精度类型为 FP32。</b></p></details>
|
|
|
+
|
|
|
+<b></b>
|
|
|
+
|
|
|
+## 2. 快速开始
|
|
|
+PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可以在本地使用 Python 体验文档场景信息抽取v4产线的效果。
|
|
|
+
|
|
|
+### 2.1 本地体验
|
|
|
+在本地使用文档场景信息抽取v4产线前,请确保您已经按照[PaddleX本地安装教程](../../../installation/installation.md)完成了PaddleX的wheel包安装。
|
|
|
+
|
|
|
+在进行模型推理之前,首先需要准备大语言模型的 api_key,PP-ChatOCRv4 支持在[百度云千帆平台](https://console.bce.baidu.com/qianfan/ais/console/onlineService)或者本地部署的标准 OpenAI 接口大模型服务。如果使用百度云千帆平台,可以参考[认证鉴权](https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Um2wxbaps) 获取 api_key。如果使用本地部署的大模型服务,可以参考[PaddleNLP大模型部署文档](https://github.com/PaddlePaddle/PaddleNLP/tree/develop/llm)进行大模型部署对话接口部署和向量化接口部署,并填写对应的 base_url 和 api_key 即可。如果需要使用多模态大模型进行数据融合,可以参考[PaddleMIX模型文档](https://github.com/PaddlePaddle/PaddleMIX/tree/develop/paddlemix/examples/ppdocbee)中的OpenAI服务部署进行多模态大模型部署,并填写对应的 base_url 和 api_key 即可。
|
|
|
+
|
|
|
+
|
|
|
+更新配置文件后,即可使用几行Python代码完成快速推理,可以使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/vehicle_certificate-1.png)测试:
|
|
|
+
|
|
|
+**注:** 如果因本地环境限制无法在本地部署多模态大模型,可以将代码中的含有“mllm”变量的行注释掉,仅使用大语言模型完成信息抽取。
|
|
|
+
|
|
|
+```python
|
|
|
+from paddlex import create_pipeline
|
|
|
+
|
|
|
+pipeline = create_pipeline(pipeline="PP-ChatOCRv4-doc",initial_predictor=False)
|
|
|
+
|
|
|
+visual_predict_res = pipeline.visual_predict(input="vehicle_certificate-1.png",
|
|
|
+ use_doc_orientation_classify=False,
|
|
|
+ use_doc_unwarping=False,
|
|
|
+ use_common_ocr=True,
|
|
|
+ use_seal_recognition=True,
|
|
|
+ use_table_recognition=True)
|
|
|
+
|
|
|
+visual_info_list = []
|
|
|
+for res in visual_predict_res:
|
|
|
+ visual_info_list.append(res["visual_info"])
|
|
|
+ layout_parsing_result = res["layout_parsing_result"]
|
|
|
+
|
|
|
+vector_info = pipeline.build_vector(visual_info_list, flag_save_bytes_vector=True,retriever_config={
|
|
|
+ "module_name": "retriever",
|
|
|
+ "model_name": "embedding-v1",
|
|
|
+ "base_url": "https://qianfan.baidubce.com/v2",
|
|
|
+ "api_type": "qianfan",
|
|
|
+ "api_key": "api_key" # your api_key
|
|
|
+})
|
|
|
+mllm_predict_res= pipeline.mllm_pred(input="vehicle_certificate-1.png",key_list=["驾驶室准乘人数"],mllm_chat_bot_config={
|
|
|
+ "module_name": "chat_bot",
|
|
|
+ "model_name": "PP-DocBee",
|
|
|
+ "base_url": "http://172.0.0.1:8080/v1/chat/completions", # your local mllm service url
|
|
|
+ "api_type": "openai",
|
|
|
+ "api_key": "api_key" # your api_key
|
|
|
+})
|
|
|
+mllm_predict_info = mllm_predict_res["mllm_res"]
|
|
|
+chat_result = pipeline.chat(
|
|
|
+ key_list=["驾驶室准乘人数"],
|
|
|
+ visual_info_list=visual_info_list,
|
|
|
+ vector_info=vector_info,
|
|
|
+ mllm_predict_info=mllm_predict_info,
|
|
|
+ chat_bot_config={
|
|
|
+ "module_name": "chat_bot",
|
|
|
+ "model_name": "ernie-3.5-8k",
|
|
|
+ "base_url": "https://qianfan.baidubce.com/v2",
|
|
|
+ "api_type": "openai",
|
|
|
+ "api_key": "api_key" # your api_key
|
|
|
+ },
|
|
|
+ retriever_config={
|
|
|
+ "module_name": "retriever",
|
|
|
+ "model_name": "embedding-v1",
|
|
|
+ "base_url": "https://qianfan.baidubce.com/v2",
|
|
|
+ "api_type": "qianfan",
|
|
|
+ "api_key": "api_key" # your api_key
|
|
|
+ }
|
|
|
+)
|
|
|
+print(chat_result)
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+运行后,输出结果如下:
|
|
|
+
|
|
|
+```
|
|
|
+{'chat_res': {'驾驶室准乘人数': '2'}}
|
|
|
+```
|
|
|
+
|
|
|
+PP-ChatOCRv4 预测的流程、API说明、产出说明如下:
|
|
|
+
|
|
|
+<details><summary>(1)调用 <code>create_pipeline</code> 方法实例化PP-ChatOCRv4产线对象。</summary>
|
|
|
+
|
|
|
+相关参数说明如下:
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>pipeline</code></td>
|
|
|
+<td>产线名称或是产线配置文件路径。如为产线名称,则必须为 PaddleX 所支持的产线。</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>device</code></td>
|
|
|
+<td>产线推理设备。支持指定GPU具体卡号,如“gpu:0”,其他硬件具体卡号,如“npu:0”,CPU如“cpu”。</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>gpu</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>use_hpip</code></td>
|
|
|
+<td>是否启用高性能推理,仅当该产线支持高性能推理时可用。</td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td><code>False</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>initial_predictor</code></td>
|
|
|
+<td>是否初始化推理模块(如果为<code>False</code>则在首次使用相关推理模块的时候进行初始化)</td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td><code>True</code></td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+</details>
|
|
|
+
|
|
|
+<details><summary>(2)调用 PP-ChatOCRv4 产线对象的 <code>visual_predict()</code> 方法获取视觉预测结果。 该方法将返回一个 generator。</summary>
|
|
|
+
|
|
|
+以下是 `visual_predict()` 方法的参数及其说明:
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>可选项</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tr>
|
|
|
+<td><code>input</code></td>
|
|
|
+<td>待预测数据,支持多种输入类型,必填</td>
|
|
|
+<td><code>Python Var|str|list</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>Python Var</b>:如 <code>numpy.ndarray</code> 表示的图像数据</li>
|
|
|
+ <li><b>str</b>:如图像文件或者PDF文件的本地路径:<code>/root/data/img.jpg</code>;<b>如URL链接</b>,如图像文件或PDF文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/demo_paper.png">示例</a>;<b>如本地目录</b>,该目录下需包含待预测图像,如本地路径:<code>/root/data/</code>(当前不支持目录中包含PDF文件的预测,PDF文件需要指定到具体文件路径)</li>
|
|
|
+ <li><b>List</b>:列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray]</code>,<code>[\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code></li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>device</code></td>
|
|
|
+<td>产线推理设备</td>
|
|
|
+<td><code>str|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>CPU</b>:如 <code>cpu</code> 表示使用 CPU 进行推理;</li>
|
|
|
+ <li><b>GPU</b>:如 <code>gpu:0</code> 表示使用第 1 块 GPU 进行推理;</li>
|
|
|
+ <li><b>NPU</b>:如 <code>npu:0</code> 表示使用第 1 块 NPU 进行推理;</li>
|
|
|
+ <li><b>XPU</b>:如 <code>xpu:0</code> 表示使用第 1 块 XPU 进行推理;</li>
|
|
|
+ <li><b>MLU</b>:如 <code>mlu:0</code> 表示使用第 1 块 MLU 进行推理;</li>
|
|
|
+ <li><b>DCU</b>:如 <code>dcu:0</code> 表示使用第 1 块 DCU 进行推理;</li>
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化时,会优先使用本地的 GPU 0号设备,如果没有,则使用 CPU 设备;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>use_doc_orientation_classify</code></td>
|
|
|
+<td>是否使用文档方向分类模块</td>
|
|
|
+<td><code>bool|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>bool</b>:<code>True</code> 或者 <code>False</code>;</li>
|
|
|
+ <li><b>None</b>:如果设置为<code>None</code>, 将默认使用产线初始化的该参数值,初始化为<code>True</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>use_doc_unwarping</code></td>
|
|
|
+<td>是否使用文档扭曲矫正模块</td>
|
|
|
+<td><code>bool|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>bool</b>:<code>True</code> 或者 <code>False</code>;</li>
|
|
|
+ <li><b>None</b>:如果设置为<code>None</code>, 将默认使用产线初始化的该参数值,初始化为<code>True</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>use_textline_orientation</code></td>
|
|
|
+<td>是否使用文本行方向分类模块</td>
|
|
|
+<td><code>bool|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>bool</b>:<code>True</code> 或者 <code>False</code>;</li>
|
|
|
+ <li><b>None</b>:如果设置为<code>None</code>, 将默认使用产线初始化的该参数值,初始化为<code>True</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>use_general_ocr</code></td>
|
|
|
+<td>是否使用 OCR 子产线</td>
|
|
|
+<td><code>bool|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>bool</b>:<code>True</code> 或者 <code>False</code>;</li>
|
|
|
+ <li><b>None</b>:如果设置为<code>None</code>, 将默认使用产线初始化的该参数值,初始化为<code>True</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>use_seal_recognition</code></td>
|
|
|
+<td>是否使用印章识别子产线</td>
|
|
|
+<td><code>bool|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>bool</b>:<code>True</code> 或者 <code>False</code>;</li>
|
|
|
+ <li><b>None</b>:如果设置为<code>None</code>, 将默认使用产线初始化的该参数值,初始化为<code>True</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>use_table_recognition</code></td>
|
|
|
+<td>是否使用表格识别子产线</td>
|
|
|
+<td><code>bool|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>bool</b>:<code>True</code> 或者 <code>False</code>;</li>
|
|
|
+ <li><b>None</b>:如果设置为<code>None</code>, 将默认使用产线初始化的该参数值,初始化为<code>True</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>layout_threshold</code></td>
|
|
|
+<td>版面模型得分阈值</td>
|
|
|
+<td><code>float|dict|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:<code>0-1</code> 之间的任意浮点数;</li>
|
|
|
+ <li><b>dict</b>: <code>{0:0.1}</code> key为类别ID,value为该类别的阈值;</li>
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化为 <code>0.5</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>layout_nms</code></td>
|
|
|
+<td>是否使用NMS</td>
|
|
|
+<td><code>bool|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>bool</b>:<code>True</code> 或者 <code>False</code>;</li>
|
|
|
+ <li><b>None</b>:如果设置为<code>None</code>, 将默认使用产线初始化的该参数值,初始化为<code>True</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>layout_unclip_ratio</code></td>
|
|
|
+<td>版面检测扩张系数</td>
|
|
|
+<td><code>float|Tuple[float,float]|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:任意大于 <code>0</code> 浮点数;</li>
|
|
|
+ <li><b>Tuple[float,float]</b>:在横纵两个方向各自的扩张系数;</li>
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化为 <code>1.0</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>layout_merge_bboxes_mode</code></td>
|
|
|
+<td>重叠框过滤方式</td>
|
|
|
+<td><code>str|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>str</b>:large,small, union.分别表示重叠框过滤时选择保留大框,小框还是同时保留</li>
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化为 <code>large</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_det_limit_side_len</code></td>
|
|
|
+<td>文本检测的图像边长限制</td>
|
|
|
+<td><code>int|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>int</b>:大于 <code>0</code> 的任意整数;</li>
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化为 <code>960</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_det_limit_type</code></td>
|
|
|
+<td>文本检测的图像边长限制类型</td>
|
|
|
+<td><code>str|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>str</b>:支持 <code>min</code> 和 <code>max</code>,<code>min</code> 表示保证图像最短边不小于 <code>det_limit_side_len</code>,<code>max</code> 表示保证图像最长边不大于 <code>limit_side_len</code></li>
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化为 <code>max</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_det_thresh</code></td>
|
|
|
+<td>检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点</td>
|
|
|
+<td><code>float|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:大于 <code>0</code> 的任意浮点数
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值 <code>0.3</code></td>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_det_box_thresh</code></td>
|
|
|
+<td>检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域</td>
|
|
|
+<td><code>float|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:大于 <code>0</code> 的任意浮点数
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值 <code>0.6</code></td>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_det_unclip_ratio</code></td>
|
|
|
+<td>文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大</td>
|
|
|
+<td><code>float|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:大于 <code>0</code> 的任意浮点数
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值 <code>2.0</code></td>
|
|
|
+</ul>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_rec_score_thresh</code></td>
|
|
|
+<td>文本识别阈值,得分大于该阈值的文本结果会被保留</td>
|
|
|
+<td><code>float|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:大于 <code>0</code> 的任意浮点数
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值 <code>0.0</code>。即不设阈值</td>
|
|
|
+</ul>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>seal_det_limit_side_len</code></td>
|
|
|
+<td>印章检测的图像边长限制</td>
|
|
|
+<td><code>int|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>int</b>:大于 <code>0</code> 的任意整数;</li>
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化为 <code>960</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>seal_det_limit_type</code></td>
|
|
|
+<td>印章检测的图像边长限制类型</td>
|
|
|
+<td><code>str|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>str</b>:支持 <code>min</code> 和 <code>max</code>,<code>min</code> 表示保证图像最短边不小于 <code>det_limit_side_len</code>,<code>max</code> 表示保证图像最长边不大于 <code>limit_side_len</code></li>
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化为 <code>max</code>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>seal_det_thresh</code></td>
|
|
|
+<td>检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是印章像素点</td>
|
|
|
+<td><code>float|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:大于 <code>0</code> 的任意浮点数
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值 <code>0.3</code></td>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>seal_det_box_thresh</code></td>
|
|
|
+<td>检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是印章区域</td>
|
|
|
+<td><code>float|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:大于 <code>0</code> 的任意浮点数
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值 <code>0.6</code></td>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>seal_det_unclip_ratio</code></td>
|
|
|
+<td>印章检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大</td>
|
|
|
+<td><code>float|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:大于 <code>0</code> 的任意浮点数
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值 <code>2.0</code></td>
|
|
|
+</ul>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>seal_rec_score_thresh</code></td>
|
|
|
+<td>印章识别阈值,得分大于该阈值的文本结果会被保留</td>
|
|
|
+<td><code>float|None</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>float</b>:大于 <code>0</code> 的任意浮点数
|
|
|
+ <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值 <code>0.0</code>。即不设阈值</td>
|
|
|
+</ul>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+</details>
|
|
|
+
|
|
|
+<details><summary>(3)对视觉预测结果进行处理。</summary>
|
|
|
+
|
|
|
+每个样本的预测结果均为 `dict` 类型,包含 `visual_info` 和 `layout_parsing_result` 两个字段。通过 `visual_info` 得到视觉信息(包含 `normal_text_dict`、`table_text_list`、`table_html_list` 等信息),并将每个样本的信息放到 `visual_info_list` 列表中,该列表的内容会在之后送入大语言模型中。
|
|
|
+
|
|
|
+当然,您也可以通过 `layout_parsing_result` 获取版面解析的结果,该结果包含文件或图片中包含的表格、文字、图片等内容,且支持打印、保存为图片、保存为`json`文件的操作:
|
|
|
+
|
|
|
+```python
|
|
|
+......
|
|
|
+for res in visual_predict_res:
|
|
|
+ visual_info_list.append(res["visual_info"])
|
|
|
+ layout_parsing_result = res["layout_parsing_result"]
|
|
|
+ layout_parsing_result.print()
|
|
|
+ layout_parsing_result.save_to_img("./output")
|
|
|
+ layout_parsing_result.save_to_json("./output")
|
|
|
+ layout_parsing_result.save_to_xlsx("./output")
|
|
|
+ layout_parsing_result.save_to_html("./output")
|
|
|
+......
|
|
|
+```
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>方法</th>
|
|
|
+<th>方法说明</th>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+
|
|
|
+<tr>
|
|
|
+<td rowspan = "3"><code>print()</code></td>
|
|
|
+<td rowspan = "3">打印结果到终端</td>
|
|
|
+<td><code>format_json</code></td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td>是否对输出内容进行使用 <code>JSON</code> 缩进格式化</td>
|
|
|
+<td><code>True</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>indent</code></td>
|
|
|
+<td><code>int</code></td>
|
|
|
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
|
|
|
+<td>4</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>ensure_ascii</code></td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
|
|
|
+<td><code>False</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td rowspan = "3"><code>save_to_json()</code></td>
|
|
|
+<td rowspan = "3">将结果保存为json格式的文件</td>
|
|
|
+<td><code>save_path</code></td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>indent</code></td>
|
|
|
+<td><code>int</code></td>
|
|
|
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
|
|
|
+<td>4</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>ensure_ascii</code></td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
|
|
|
+<td><code>False</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>save_to_img()</code></td>
|
|
|
+<td>将中间各个模块的可视化图像保存在png格式的图像</td>
|
|
|
+<td><code>save_path</code></td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>保存的文件路径,支持目录或文件路径</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>save_to_html()</code></td>
|
|
|
+<td>将文件中的表格保存为html格式的文件</td>
|
|
|
+<td><code>save_path</code></td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>保存的文件路径,支持目录或文件路径</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>save_to_xlsx()</code></td>
|
|
|
+<td>将文件中的表格保存为xlsx格式的文件</td>
|
|
|
+<td><code>save_path</code></td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>保存的文件路径,支持目录或文件路径</td>
|
|
|
+<td>无</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+
|
|
|
+- 调用`print()` 方法会将结果打印到终端,打印到终端的内容解释如下:
|
|
|
+ - `input_path`: `(str)` 待预测图像的输入路径
|
|
|
+
|
|
|
+ - `page_index`: `(Union[int, None])` 如果输入是PDF文件,则表示当前是PDF的第几页,否则为 `None`
|
|
|
+
|
|
|
+ - `model_settings`: `(Dict[str, bool])` 配置产线所需的模型参数
|
|
|
+
|
|
|
+ - `use_doc_preprocessor`: `(bool)` 控制是否启用文档预处理子产线
|
|
|
+ - `use_general_ocr`: `(bool)` 控制是否启用 OCR 子产线
|
|
|
+ - `use_seal_recognition`: `(bool)` 控制是否启用印章识别子产线
|
|
|
+ - `use_table_recognition`: `(bool)` 控制是否启用表格识别子产线
|
|
|
+ - `use_formula_recognition`: `(bool)` 控制是否启用公式识别子产线
|
|
|
+
|
|
|
+ - `parsing_res_list`: `(List[Dict])` 解析结果的列表,每个元素为一个字典,列表顺序为解析后的阅读顺序。
|
|
|
+ - `block_bbox`: `(np.ndarray)` 版面区域的边界框。
|
|
|
+ - `block_label`: `(str)` 版面区域的标签,例如`text`, `table`等。
|
|
|
+ - `block_content`: `(str)` 内容为版面区域内的内容。
|
|
|
+
|
|
|
+ - `overall_ocr_res`: `(Dict[str, Union[List[str], List[float], numpy.ndarray]])` 全局 OCR 结果的字典
|
|
|
+ - `input_path`: `(Union[str, None])` 图像OCR子产线接受的图像路径,当输入为`numpy.ndarray`时,保存为`None`
|
|
|
+ - `model_settings`: `(Dict)` OCR子产线的模型配置参数
|
|
|
+ - `dt_polys`: `(List[numpy.ndarray])` 文本检测的多边形框列表。每个检测框由4个顶点坐标构成的numpy数组表示,数组shape为(4, 2),数据类型为int16
|
|
|
+ - `dt_scores`: `(List[float])` 文本检测框的置信度列表
|
|
|
+ - `text_det_params`: `(Dict[str, Dict[str, int, float]])` 文本检测模块的配置参数
|
|
|
+ - `limit_side_len`: `(int)` 图像预处理时的边长限制值
|
|
|
+ - `limit_type`: `(str)` 边长限制的处理方式
|
|
|
+ - `thresh`: `(float)` 文本像素分类的置信度阈值
|
|
|
+ - `box_thresh`: `(float)` 文本检测框的置信度阈值
|
|
|
+ - `unclip_ratio`: `(float)` 文本检测框的膨胀系数
|
|
|
+ - `text_type`: `(str)` 文本检测的类型,当前固定为"general"
|
|
|
+
|
|
|
+ - `text_type`: `(str)` 文本检测的类型,当前固定为"general"
|
|
|
+ - `textline_orientation_angles`: `(List[int])` 文本行方向分类的预测结果。启用时返回实际角度值(如[0,0,1]
|
|
|
+ - `text_rec_score_thresh`: `(float)` 文本识别结果的过滤阈值
|
|
|
+ - `rec_texts`: `(List[str])` 文本识别结果列表,仅包含置信度超过`text_rec_score_thresh`的文本
|
|
|
+ - `rec_scores`: `(List[float])` 文本识别的置信度列表,已按`text_rec_score_thresh`过滤
|
|
|
+ - `rec_polys`: `(List[numpy.ndarray])` 经过置信度过滤的文本检测框列表,格式同`dt_polys`
|
|
|
+
|
|
|
+ - `formula_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` 公式识别结果列表,每个元素为一个字典
|
|
|
+ - `rec_formula`: `(str)` 公式识别结果
|
|
|
+ - `rec_polys`: `(numpy.ndarray)` 公式检测框,shape为(4, 2),dtype为int16
|
|
|
+ - `formula_region_id`: `(int)` 公式所在的区域编号
|
|
|
+
|
|
|
+ - `seal_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` 印章识别结果列表,每个元素为一个字典
|
|
|
+ - `input_path`: `(str)` 印章图像的输入路径
|
|
|
+ - `model_settings`: `(Dict)` 印章识别子产线的模型配置参数
|
|
|
+ - `dt_polys`: `(List[numpy.ndarray])` 印章检测框列表,格式同`dt_polys`
|
|
|
+ - `text_det_params`: `(Dict[str, Dict[str, int, float]])` 印章检测模块的配置参数, 具体参数含义同上
|
|
|
+ - `text_type`: `(str)` 印章检测的类型,当前固定为"seal"
|
|
|
+ - `text_rec_score_thresh`: `(float)` 印章识别结果的过滤阈值
|
|
|
+ - `rec_texts`: `(List[str])` 印章识别结果列表,仅包含置信度超过`text_rec_score_thresh`的文本
|
|
|
+ - `rec_scores`: `(List[float])` 印章识别的置信度列表,已按`text_rec_score_thresh`过滤
|
|
|
+ - `rec_polys`: `(List[numpy.ndarray])` 经过置信度过滤的印章检测框列表,格式同`dt_polys`
|
|
|
+ - `rec_boxes`: `(numpy.ndarray)` 检测框的矩形边界框数组,shape为(n, 4),dtype为int16。每一行表示一个矩形
|
|
|
+
|
|
|
+ - `table_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` 表格识别结果列表,每个元素为一个字典
|
|
|
+ - `cell_box_list`: `(List[numpy.ndarray])` 表格单元格的边界框列表
|
|
|
+ - `pred_html`: `(str)` 表格的HTML格式字符串
|
|
|
+ - `table_ocr_pred`: `(dict)` 表格的OCR识别结果
|
|
|
+ - `rec_polys`: `(List[numpy.ndarray])` 单元格的检测框列表
|
|
|
+ - `rec_texts`: `(List[str])` 单元格的识别结果
|
|
|
+ - `rec_scores`: `(List[float])` 单元格的识别置信度
|
|
|
+ - `rec_boxes`: `(numpy.ndarray)` 检测框的矩形边界框数组,shape为(n, 4),dtype为int16。每一行表示一个矩形
|
|
|
+
|
|
|
+- 调用`save_to_json()` 方法会将上述内容保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_img_basename}.json`,如果指定为文件,则直接保存到该文件中。由于json文件不支持保存numpy数组,因此会将其中的`numpy.array`类型转换为列表形式。
|
|
|
+- 调用`save_to_img()` 方法会将可视化结果保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_img_basename}_ocr_res_img.{your_img_extension}`,如果指定为文件,则直接保存到该文件中。(产线通常包含较多结果图片,不建议直接指定为具体的文件路径,否则多张图会被覆盖,仅保留最后一张图)
|
|
|
+
|
|
|
+此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>属性</th>
|
|
|
+<th>属性说明</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tr>
|
|
|
+<td rowspan = "1"><code>json</code></td>
|
|
|
+<td rowspan = "1">获取预测的 <code>json</code> 格式的结果</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td rowspan = "2"><code>img</code></td>
|
|
|
+<td rowspan = "2">获取格式为 <code>dict</code> 的可视化图像</td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+
|
|
|
+- `json` 属性获取的预测结果为dict类型的数据,相关内容与调用 `save_to_json()` 方法保存的内容一致。
|
|
|
+- `img` 属性返回的预测结果是一个字典类型的数据。其中,键分别为 `layout_det_res`、`overall_ocr_res`、`text_paragraphs_ocr_res`、`formula_res_region1`、`table_cell_img` 和 `seal_res_region1`,对应的值是 `Image.Image` 对象:分别用于显示版面区域检测、OCR、OCR文本段落、公式、表格和印章结果的可视化图像。如果没有使用可选模块,则字典中只包含 `layout_det_res`。
|
|
|
+</details>
|
|
|
+
|
|
|
+<details><summary>(4)调用PP-ChatOCRv4的产线对象的 <code>build_vector()</code> 方法,对文本内容进行向量构建。</summary>
|
|
|
+
|
|
|
+以下是 `build_vector()` 方法的参数及其说明:
|
|
|
+
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>可选项</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tr>
|
|
|
+<td><code>visual_info</code></td>
|
|
|
+<td>视觉信息,可以是包含视觉信息的字典,或者由这些字典组成的列表</td>
|
|
|
+<td><code>list|dict</code></td>
|
|
|
+<td>
|
|
|
+<code>None</code>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>min_characters</code></td>
|
|
|
+<td>最小字符数量</td>
|
|
|
+<td><code>int</code></td>
|
|
|
+<td>
|
|
|
+大于0的正整数,可以根据大语言模型支持的token长度来决定
|
|
|
+</td>
|
|
|
+<td><code>3500</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>block_size</code></td>
|
|
|
+<td>长文本建立向量库时分块大小</td>
|
|
|
+<td><code>int</code></td>
|
|
|
+<td>
|
|
|
+大于0的正整数,可以根据大语言模型支持的token长度来决定
|
|
|
+</td>
|
|
|
+<td><code>300</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>flag_save_bytes_vector</code></td>
|
|
|
+<td>文字是否保存为二进制文件</td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td>
|
|
|
+<code>True|False</code>
|
|
|
+</td>
|
|
|
+<td><code>False</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>retriever_config</code></td>
|
|
|
+<td>向量检索大模型配置参数,内容参考配置文件中的“LLM_Retriever”字段</td>
|
|
|
+<td><code>dict</code></td>
|
|
|
+<td>
|
|
|
+<code>None</code>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+</table>
|
|
|
+该方法会返回一个包含视觉文本信息的字典,字典的内容如下:
|
|
|
+
|
|
|
+- `flag_save_bytes_vector`:`(bool)`是否将结果保存为二进制文件
|
|
|
+- `flag_too_short_text`:`(bool)`是否文本长度小于最小字符数量
|
|
|
+- `vector`: `(str|list)` 文本的二进制内容或者文本内容,取决于`flag_save_bytes_vector`和`min_characters`的值,如果`flag_save_bytes_vector=True`且文本长度大于等于最小字符数量,则返回二进制内容;否则返回原始的文本。
|
|
|
+</details>
|
|
|
+
|
|
|
+<details><summary>(5)调用PP-ChatOCRv4的产线对象的 <code>mllm_pred()</code> 方法,获取多模态大模型抽取结果。</summary>
|
|
|
+
|
|
|
+以下是 `mllm_pred()` 方法的参数及其说明:
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>可选项</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>input</code></td>
|
|
|
+<td>待预测数据,支持多种输入类型,必填</td>
|
|
|
+<td><code>Python Var|str</code></td>
|
|
|
+<td>
|
|
|
+<ul>
|
|
|
+ <li><b>Python Var</b>:如 <code>numpy.ndarray</code> 表示的图像数据</li>
|
|
|
+ <li><b>str</b>:如图像文件或者单页PDF文件的本地路径:<code>/root/data/img.jpg</code>;<b>如URL链接</b>,如图像文件或单页PDF文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/demo_paper.png">示例</a>;</li>
|
|
|
+</ul>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>key_list</code></td>
|
|
|
+<td>用于提取信息的单个键或键列表</td>
|
|
|
+<td><code>Union[str, List[str]]</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>mllm_chat_bot_config</code></td>
|
|
|
+<td>多模态大模型配置参数,内容参考配置文件中的“MLLM_Chat”字段</td>
|
|
|
+<td><code>dict</code></td>
|
|
|
+<td>
|
|
|
+<code>None</code>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
+<details><summary>(6)调用PP-ChatOCRv4的产线对象的 <code>chat()</code> 方法,对关键信息进行抽取。</summary>
|
|
|
+
|
|
|
+以下是 `chat()` 方法的参数及其说明:
|
|
|
+
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>参数</th>
|
|
|
+<th>参数说明</th>
|
|
|
+<th>参数类型</th>
|
|
|
+<th>可选项</th>
|
|
|
+<th>默认值</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>key_list</code></td>
|
|
|
+<td>用于提取信息的单个键或键列表</td>
|
|
|
+<td><code>Union[str, List[str]]</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>visual_info</code></td>
|
|
|
+<td>视觉信息结果</td>
|
|
|
+<td><code>List[dict]</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>use_vector_retrieval</code></td>
|
|
|
+<td>是否使用向量检索</td>
|
|
|
+<td><code>bool</code></td>
|
|
|
+<td><code>True|False</code></td>
|
|
|
+<td><code>True</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>vector_info</code></td>
|
|
|
+<td>用于检索的向量信息</td>
|
|
|
+<td><code>dict</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>min_characters</code></td>
|
|
|
+<td>所需的最小字符数</td>
|
|
|
+<td><code>int</code></td>
|
|
|
+<td>大于0的正整数</td>
|
|
|
+<td><code>3500</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_task_description</code></td>
|
|
|
+<td>文本任务的描述</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_output_format</code></td>
|
|
|
+<td>文本结果的输出格式</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_rules_str</code></td>
|
|
|
+<td>生成文本结果的规则</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_few_shot_demo_text_content</code></td>
|
|
|
+<td>用于少样本演示的文本内容</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text_few_shot_demo_key_value_list</code></td>
|
|
|
+<td>用于少样本演示的键值列表</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>table_task_description</code></td>
|
|
|
+<td>表任务的描述</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>table_output_format</code></td>
|
|
|
+<td>表结果的输出格式</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>table_rules_str</code></td>
|
|
|
+<td>生成表结果的规则</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>table_few_shot_demo_text_content</code></td>
|
|
|
+<td>表少样本演示的文本内容</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>table_few_shot_demo_key_value_list</code></td>
|
|
|
+<td>表少样本演示的键值列表</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>mllm_predict_info</code></td>
|
|
|
+<td>多模态大模型结果</td>
|
|
|
+<td><code>dict</code></td>
|
|
|
+<td>
|
|
|
+<code>None</code>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<td><code>mllm_integration_strategy</code></td>
|
|
|
+<td>多模态大模型和大语言模型数据融合策略,支持单独使用其中一个或者融合两者结果</td>
|
|
|
+<td><code>str</code></td>
|
|
|
+<td>
|
|
|
+<code>"integration"</code>
|
|
|
+</td>
|
|
|
+<td><code>"integration", "llm_only" and "mllm_only"</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>chat_bot_config</code></td>
|
|
|
+<td>大语言模型配置信息,内容参考产线配置文件“LLM_Chat”字段</td>
|
|
|
+<td><code>dict</code></td>
|
|
|
+<td>
|
|
|
+<code>None</code>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>retriever_config</code></td>
|
|
|
+<td>向量检索大模型配置参数,内容参考配置文件中的“LLM_Retriever”字段</td>
|
|
|
+<td><code>dict</code></td>
|
|
|
+<td>
|
|
|
+<code>None</code>
|
|
|
+</td>
|
|
|
+<td><code>None</code></td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+
|
|
|
+该方法会将结果打印到终端,打印到终端的内容解释如下:
|
|
|
+ - `chat_res`: `(dict)` 提取信息的结果,是一个字典,包含了待抽取的键和对应的值。
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
+## 3. 开发集成/部署
|
|
|
+如果产线可以达到您对产线推理速度和精度的要求,您可以直接进行开发集成/部署。
|
|
|
+
|
|
|
+若您需要将产线直接应用在您的Python项目中,可以参考 [2.2 本地体验](#22-本地体验)中的示例代码。
|
|
|
+
|
|
|
+此外,PaddleX 也提供了其他三种部署方式,详细说明如下:
|
|
|
+
|
|
|
+🚀 <b>高性能推理</b>:在实际生产环境中,许多应用对部署策略的性能指标(尤其是响应速度)有着较严苛的标准,以确保系统的高效运行与用户体验的流畅性。为此,PaddleX 提供高性能推理插件,旨在对模型推理及前后处理进行深度性能优化,实现端到端流程的显著提速,详细的高性能推理流程请参考[PaddleX高性能推理指南](../../../pipeline_deploy/high_performance_inference.md)。
|
|
|
+
|
|
|
+☁️ <b>服务化部署</b>:服务化部署是实际生产环境中常见的一种部署形式。通过将推理功能封装为服务,客户端可以通过网络请求来访问这些服务,以获取推理结果。PaddleX 支持多种产线服务化部署方案,详细的产线服务化部署流程请参考[PaddleX服务化部署指南](../../../pipeline_deploy/serving.md)。
|
|
|
+
|
|
|
+以下是基础服务化部署的API参考与多语言服务调用示例:
|
|
|
+
|
|
|
+<details><summary>API参考</summary>
|
|
|
+
|
|
|
+<p>对于服务提供的主要操作:</p>
|
|
|
+<ul>
|
|
|
+<li>HTTP请求方法为POST。</li>
|
|
|
+<li>请求体和响应体均为JSON数据(JSON对象)。</li>
|
|
|
+<li>当请求处理成功时,响应状态码为<code>200</code>,响应体的属性如下:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>logId</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>请求的UUID。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>errorCode</code></td>
|
|
|
+<td><code>integer</code></td>
|
|
|
+<td>错误码。固定为<code>0</code>。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>errorMsg</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>错误说明。固定为<code>"Success"</code>。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>result</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>操作结果。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<ul>
|
|
|
+<li>当请求处理未成功时,响应体的属性如下:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>logId</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>请求的UUID。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>errorCode</code></td>
|
|
|
+<td><code>integer</code></td>
|
|
|
+<td>错误码。与响应状态码相同。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>errorMsg</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>错误说明。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p>服务提供的主要操作如下:</p>
|
|
|
+<ul>
|
|
|
+<li><b><code>analyzeImages</code></b></li>
|
|
|
+</ul>
|
|
|
+<p>使用计算机视觉模型对图像进行分析,获得OCR、表格识别结果等,并提取图像中的关键信息。</p>
|
|
|
+<p><code>POST /chatocr-visual</code></p>
|
|
|
+<ul>
|
|
|
+<li>请求体的属性如下:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+<th>是否必填</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>file</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>服务器可访问的图像文件或PDF文件的URL,或上述类型文件内容的Base64编码结果。对于超过10页的PDF文件,只有前10页的内容会被使用。</td>
|
|
|
+<td>是</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>fileType</code></td>
|
|
|
+<td><code>integer</code></td>
|
|
|
+<td>文件类型。<code>0</code>表示PDF文件,<code>1</code>表示图像文件。若请求体无此属性,则将根据URL推断文件类型。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>useImgOrientationCls</code></td>
|
|
|
+<td><code>boolean</code></td>
|
|
|
+<td>是否启用文档图像方向分类功能。默认启用该功能。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>useImgUnwarping</code></td>
|
|
|
+<td><code>boolean</code></td>
|
|
|
+<td>是否启用文本图像矫正功能。默认启用该功能。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>useSealTextDet</code></td>
|
|
|
+<td><code>boolean</code></td>
|
|
|
+<td>是否启用印章文本检测功能。默认启用该功能。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>inferenceParams</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>推理参数。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><code>inferenceParams</code>的属性如下:</p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+<th>是否必填</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>maxLongSide</code></td>
|
|
|
+<td><code>integer</code></td>
|
|
|
+<td>推理时,若文本检测模型的输入图像较长边的长度大于<code>maxLongSide</code>,则将对图像进行缩放,使其较长边的长度等于<code>maxLongSide</code>。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<ul>
|
|
|
+<li>请求处理成功时,响应体的<code>result</code>具有如下属性:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>visualResults</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>使用计算机视觉模型得到的分析结果。数组长度为1(对于图像输入)或文档页数与10中的较小者(对于PDF输入)。对于PDF输入,数组中的每个元素依次表示PDF文件中每一页的处理结果。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>visualInfo</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>图像中的关键信息,可用作其他操作的输入。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>dataInfo</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>输入数据信息。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><code>visualResults</code>中的每个元素为一个<code>object</code>,具有如下属性:</p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>texts</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>文本位置、内容和得分。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>tables</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>表格位置和内容。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>inputImage</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>输入图像。图像为JPEG格式,使用Base64编码。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>layoutImage</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>版面区域检测结果图。图像为JPEG格式,使用Base64编码。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>ocrImage</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>OCR结果图。图像为JPEG格式,使用Base64编码。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><code>texts</code>中的每个元素为一个<code>object</code>,具有如下属性:</p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>poly</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>文本位置。数组中元素依次为包围文本的多边形的顶点坐标。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>text</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>文本内容。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>score</code></td>
|
|
|
+<td><code>number</code></td>
|
|
|
+<td>文本识别得分。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><code>tables</code>中的每个元素为一个<code>object</code>,具有如下属性:</p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>bbox</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>表格位置。数组中元素依次为边界框左上角x坐标、左上角y坐标、右下角x坐标以及右下角y坐标。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>html</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>HTML格式的表格识别结果。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<ul>
|
|
|
+<li><b><code>buildVectorStore</code></b></li>
|
|
|
+</ul>
|
|
|
+<p>构建向量数据库。</p>
|
|
|
+<p><code>POST /chatocr-vector</code></p>
|
|
|
+<ul>
|
|
|
+<li>请求体的属性如下:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+<th>是否必填</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>visualInfo</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>图像中的关键信息。由<code>analyzeImages</code>操作提供。</td>
|
|
|
+<td>是</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>minChars</code></td>
|
|
|
+<td><code>integer</code></td>
|
|
|
+<td>启用向量数据库的最小数据长度。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>llmRequestInterval</code></td>
|
|
|
+<td><code>number</code></td>
|
|
|
+<td>调用大语言模型API的间隔时间。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>llmName</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>大语言模型名称。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>llmParams</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>大语言模型API参数。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p>当前,<code>llmParams</code> 可以采用如下形式之一:</p>
|
|
|
+<pre><code class="language-json">{
|
|
|
+"apiType": "qianfan",
|
|
|
+"apiKey": "{千帆平台API key}",
|
|
|
+"secretKey": "{千帆平台secret key}"
|
|
|
+}
|
|
|
+</code></pre>
|
|
|
+<pre><code class="language-json">{
|
|
|
+"apiType": "aistudio",
|
|
|
+"accessToken": "{星河社区access token}"
|
|
|
+}
|
|
|
+</code></pre>
|
|
|
+<ul>
|
|
|
+<li>请求处理成功时,响应体的<code>result</code>具有如下属性:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>vectorStore</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>向量数据库序列化结果,可用作其他操作的输入。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<ul>
|
|
|
+<li><b><code>retrieveKnowledge</code></b></li>
|
|
|
+</ul>
|
|
|
+<p>进行知识检索。</p>
|
|
|
+<p><code>POST /chatocr-retrieval</code></p>
|
|
|
+<ul>
|
|
|
+<li>请求体的属性如下:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+<th>是否必填</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>keys</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>关键词列表。</td>
|
|
|
+<td>是</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>vectorStore</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>向量数据库序列化结果。由<code>buildVectorStore</code>操作提供。</td>
|
|
|
+<td>是</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>llmName</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>大语言模型名称。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>llmParams</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>大语言模型API参数。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p>当前,<code>llmParams</code> 可以采用如下形式之一:</p>
|
|
|
+<pre><code class="language-json">{
|
|
|
+"apiType": "qianfan",
|
|
|
+"apiKey": "{千帆平台API key}",
|
|
|
+"secretKey": "{千帆平台secret key}"
|
|
|
+}
|
|
|
+</code></pre>
|
|
|
+<pre><code class="language-json">{
|
|
|
+"apiType": "aistudio",
|
|
|
+"accessToken": "{星河社区access token}"
|
|
|
+}
|
|
|
+</code></pre>
|
|
|
+<ul>
|
|
|
+<li>请求处理成功时,响应体的<code>result</code>具有如下属性:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>retrievalResult</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>知识检索结果,可用作其他操作的输入。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<ul>
|
|
|
+<li><b><code>chat</code></b></li>
|
|
|
+</ul>
|
|
|
+<p>与大语言模型交互,利用大语言模型提炼关键信息。</p>
|
|
|
+<p><code>POST /chatocr-chat</code></p>
|
|
|
+<ul>
|
|
|
+<li>请求体的属性如下:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+<th>是否必填</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>keys</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>关键词列表。</td>
|
|
|
+<td>是</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>visualInfo</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>图像中的关键信息。由<code>analyzeImages</code>操作提供。</td>
|
|
|
+<td>是</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>vectorStore</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>向量数据库序列化结果。由<code>buildVectorStore</code>操作提供。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>retrievalResult</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>知识检索结果。由<code>retrieveKnowledge</code>操作提供。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>taskDescription</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>提示词任务。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>rules</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>提示词规则。用于自定义信息抽取规则,例如规范输出格式。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>fewShot</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>提示词示例。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>llmName</code></td>
|
|
|
+<td><code>string</code></td>
|
|
|
+<td>大语言模型名称。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>llmParams</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>大语言模型API参数。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>returnPrompts</code></td>
|
|
|
+<td><code>boolean</code></td>
|
|
|
+<td>是否返回使用的提示词。默认禁用。</td>
|
|
|
+<td>否</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p>当前,<code>llmParams</code> 可以采用如下形式之一:</p>
|
|
|
+<pre><code class="language-json">{
|
|
|
+"apiType": "qianfan",
|
|
|
+"apiKey": "{千帆平台API key}",
|
|
|
+"secretKey": "{千帆平台secret key}"
|
|
|
+}
|
|
|
+</code></pre>
|
|
|
+<pre><code class="language-json">{
|
|
|
+"apiType": "aistudio",
|
|
|
+"accessToken": "{星河社区access token}"
|
|
|
+}
|
|
|
+</code></pre>
|
|
|
+<ul>
|
|
|
+<li>请求处理成功时,响应体的<code>result</code>具有如下属性:</li>
|
|
|
+</ul>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>chatResult</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>关键信息抽取结果。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>prompts</code></td>
|
|
|
+<td><code>object</code></td>
|
|
|
+<td>使用的提示词。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table>
|
|
|
+<p><code>prompts</code>的属性如下:</p>
|
|
|
+<table>
|
|
|
+<thead>
|
|
|
+<tr>
|
|
|
+<th>名称</th>
|
|
|
+<th>类型</th>
|
|
|
+<th>含义</th>
|
|
|
+</tr>
|
|
|
+</thead>
|
|
|
+<tbody>
|
|
|
+<tr>
|
|
|
+<td><code>ocr</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>OCR提示词。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>table</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>表格提示词。</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>html</code></td>
|
|
|
+<td><code>array</code></td>
|
|
|
+<td>HTML提示词。</td>
|
|
|
+</tr>
|
|
|
+</tbody>
|
|
|
+</table></details>
|
|
|
+
|
|
|
+<details><summary>多语言调用服务示例</summary>
|
|
|
+
|
|
|
+<details>
|
|
|
+<summary>Python</summary>
|
|
|
+
|
|
|
+
|
|
|
+<pre><code class="language-python">import base64
|
|
|
+import pprint
|
|
|
+import sys
|
|
|
+
|
|
|
+import requests
|
|
|
+
|
|
|
+
|
|
|
+API_BASE_URL = "http://0.0.0.0:8080"
|
|
|
+API_KEY = "{千帆平台API key}"
|
|
|
+SECRET_KEY = "{千帆平台secret key}"
|
|
|
+LLM_NAME = "ernie-3.5"
|
|
|
+LLM_PARAMS = {
|
|
|
+ "apiType": "qianfan",
|
|
|
+ "apiKey": API_KEY,
|
|
|
+ "secretKey": SECRET_KEY,
|
|
|
+}
|
|
|
+
|
|
|
+file_path = "./demo.jpg"
|
|
|
+keys = ["电话"]
|
|
|
+
|
|
|
+with open(file_path, "rb") as file:
|
|
|
+ file_bytes = file.read()
|
|
|
+ file_data = base64.b64encode(file_bytes).decode("ascii")
|
|
|
+
|
|
|
+payload = {
|
|
|
+ "file": file_data,
|
|
|
+ "fileType": 1,
|
|
|
+ "useImgOrientationCls": True,
|
|
|
+ "useImgUnwarping": True,
|
|
|
+ "useSealTextDet": True,
|
|
|
+}
|
|
|
+resp_visual = requests.post(url=f"{API_BASE_URL}/chatocr-visual", json=payload)
|
|
|
+if resp_visual.status_code != 200:
|
|
|
+ print(
|
|
|
+ f"Request to chatocr-visual failed with status code {resp_visual.status_code}.",
|
|
|
+ file=sys.stderr,
|
|
|
+ )
|
|
|
+ pprint.pp(resp_visual.json())
|
|
|
+ sys.exit(1)
|
|
|
+result_visual = resp_visual.json()["result"]
|
|
|
+
|
|
|
+for i, res in enumerate(result_visual["visualResults"]):
|
|
|
+ print("Texts:")
|
|
|
+ pprint.pp(res["texts"])
|
|
|
+ print("Tables:")
|
|
|
+ pprint.pp(res["tables"])
|
|
|
+ layout_img_path = f"layout_{i}.jpg"
|
|
|
+ with open(layout_img_path, "wb") as f:
|
|
|
+ f.write(base64.b64decode(res["layoutImage"]))
|
|
|
+ ocr_img_path = f"ocr_{i}.jpg"
|
|
|
+ with open(ocr_img_path, "wb") as f:
|
|
|
+ f.write(base64.b64decode(res["ocrImage"]))
|
|
|
+ print(f"Output images saved at {layout_img_path} and {ocr_img_path}")
|
|
|
+
|
|
|
+payload = {
|
|
|
+ "visualInfo": result_visual["visualInfo"],
|
|
|
+ "minChars": 200,
|
|
|
+ "llmRequestInterval": 1000,
|
|
|
+ "llmName": LLM_NAME,
|
|
|
+ "llmParams": LLM_PARAMS,
|
|
|
+}
|
|
|
+resp_vector = requests.post(url=f"{API_BASE_URL}/chatocr-vector", json=payload)
|
|
|
+if resp_vector.status_code != 200:
|
|
|
+ print(
|
|
|
+ f"Request to chatocr-vector failed with status code {resp_vector.status_code}.",
|
|
|
+ file=sys.stderr,
|
|
|
+ )
|
|
|
+ pprint.pp(resp_vector.json())
|
|
|
+ sys.exit(1)
|
|
|
+result_vector = resp_vector.json()["result"]
|
|
|
+
|
|
|
+payload = {
|
|
|
+ "keys": keys,
|
|
|
+ "vectorStore": result_vector["vectorStore"],
|
|
|
+ "llmName": LLM_NAME,
|
|
|
+ "llmParams": LLM_PARAMS,
|
|
|
+}
|
|
|
+resp_retrieval = requests.post(url=f"{API_BASE_URL}/chatocr-retrieval", json=payload)
|
|
|
+if resp_retrieval.status_code != 200:
|
|
|
+ print(
|
|
|
+ f"Request to chatocr-retrieval failed with status code {resp_retrieval.status_code}.",
|
|
|
+ file=sys.stderr,
|
|
|
+ )
|
|
|
+ pprint.pp(resp_retrieval.json())
|
|
|
+ sys.exit(1)
|
|
|
+result_retrieval = resp_retrieval.json()["result"]
|
|
|
+
|
|
|
+payload = {
|
|
|
+ "keys": keys,
|
|
|
+ "visualInfo": result_visual["visualInfo"],
|
|
|
+ "vectorStore": result_vector["vectorStore"],
|
|
|
+ "retrievalResult": result_retrieval["retrievalResult"],
|
|
|
+ "taskDescription": "",
|
|
|
+ "rules": "",
|
|
|
+ "fewShot": "",
|
|
|
+ "llmName": LLM_NAME,
|
|
|
+ "llmParams": LLM_PARAMS,
|
|
|
+ "returnPrompts": True,
|
|
|
+}
|
|
|
+resp_chat = requests.post(url=f"{API_BASE_URL}/chatocr-chat", json=payload)
|
|
|
+if resp_chat.status_code != 200:
|
|
|
+ print(
|
|
|
+ f"Request to chatocr-chat failed with status code {resp_chat.status_code}.",
|
|
|
+ file=sys.stderr,
|
|
|
+ )
|
|
|
+ pprint.pp(resp_chat.json())
|
|
|
+ sys.exit(1)
|
|
|
+result_chat = resp_chat.json()["result"]
|
|
|
+print("\nPrompts:")
|
|
|
+pprint.pp(result_chat["prompts"])
|
|
|
+print("Final result:")
|
|
|
+print(result_chat["chatResult"])
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+
|
|
|
+<b>注</b>:请在 `API_KEY`、`SECRET_KEY` 处填入您的 API key 和 secret key。</details>
|
|
|
+</details>
|
|
|
+<br/>
|
|
|
+
|
|
|
+📱 <b>端侧部署</b>:端侧部署是一种将计算和数据处理功能放在用户设备本身上的方式,设备可以直接处理数据,而不需要依赖远程的服务器。PaddleX 支持将模型部署在 Android 等端侧设备上,详细的端侧部署流程请参考[PaddleX端侧部署指南](../../../pipeline_deploy/edge_deploy.md)。
|
|
|
+您可以根据需要选择合适的方式部署模型产线,进而进行后续的 AI 应用集成。
|
|
|
+
|
|
|
+## 4. 二次开发
|
|
|
+如果文档场景信息抽取v4产线提供的默认模型权重在您的场景中,精度或速度不满意,您可以尝试利用<b>您自己拥有的特定领域或应用场景的数据</b>对现有模型进行进一步的<b>微调</b>,以提升通用表格识别产线的在您的场景中的识别效果。
|
|
|
+
|
|
|
+### 4.1 模型微调
|
|
|
+由于文档场景信息抽取v4产线包含若干模块,模型产线的效果如果不及预期,可能来自于其中任何一个模块。您可以对提取效果差的 case 进行分析,通过可视化图像,确定是哪个模块存在问题,并参考以下表格中对应的微调教程链接进行模型微调。
|
|
|
+
|
|
|
+
|
|
|
+<table>
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>情形</th>
|
|
|
+ <th>微调模块</th>
|
|
|
+ <th>微调参考链接</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <tr>
|
|
|
+ <td>版面区域检测不准,如印章、表格未检出等</td>
|
|
|
+ <td>版面区域检测模块</td>
|
|
|
+ <td><a href="../../../module_usage/tutorials/ocr_modules/layout_detection.md">链接</a></td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>表格结构识别不准</td>
|
|
|
+ <td>表格结构识别</td>
|
|
|
+ <td><a href="../../../module_usage/tutorials/ocr_modules/table_structure_recognition.md">链接</a></td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>印章文本存在漏检</td>
|
|
|
+ <td>印章文本检测模块</td>
|
|
|
+ <td><a href="../../../module_usage/tutorials/ocr_modules/seal_text_detection.md">链接</a></td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>文本存在漏检</td>
|
|
|
+ <td>文本检测模块</td>
|
|
|
+ <td><a href="../../../module_usage/tutorials/ocr_modules/text_detection.md">链接</a></td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>文本内容都不准</td>
|
|
|
+ <td>文本识别模块</td>
|
|
|
+ <td><a href="../../../module_usage/tutorials/ocr_modules/text_recognition.md">链接</a></td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>垂直或者旋转文本行矫正不准</td>
|
|
|
+ <td>文本行方向分类模块</td>
|
|
|
+ <td><a href="../../../module_usage/tutorials/ocr_modules/textline_orientation_classification.md">链接</a></td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>整图旋转矫正不准</td>
|
|
|
+ <td>文档图像方向分类模块</td>
|
|
|
+ <td><a href="../../../module_usage/tutorials/ocr_modules/doc_img_orientation_classification.md">链接</a></td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>图像扭曲矫正不准</td>
|
|
|
+ <td>文本图像矫正模块</td>
|
|
|
+ <td>暂不支持微调</td>
|
|
|
+ </tr>
|
|
|
+ </tbody>
|
|
|
+</table>
|
|
|
+
|
|
|
+
|
|
|
+### 4.2 模型应用
|
|
|
+当您使用私有数据集完成微调训练后,可获得本地模型权重文件。
|
|
|
+
|
|
|
+若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径替换至产线配置文件中的对应位置即可:
|
|
|
+
|
|
|
+```yaml
|
|
|
+......
|
|
|
+SubModules:
|
|
|
+ TextDetection:
|
|
|
+ module_name: text_detection
|
|
|
+ model_name: PP-OCRv4_server_det
|
|
|
+ model_dir: null # 替换为微调后的文本检测模型权重路径
|
|
|
+ limit_side_len: 960
|
|
|
+ limit_type: max
|
|
|
+ thresh: 0.3
|
|
|
+ box_thresh: 0.6
|
|
|
+ unclip_ratio: 2.0
|
|
|
+
|
|
|
+ TextRecognition:
|
|
|
+ module_name: text_recognition
|
|
|
+ model_name: PP-OCRv4_server_rec
|
|
|
+ model_dir: null # 替换为微调后的文本检测模型权重路径
|
|
|
+ batch_size: 1
|
|
|
+ score_thresh: 0
|
|
|
+......
|
|
|
+```
|
|
|
+
|
|
|
+随后, 参考[2.2 本地体验](#22-本地体验)中的命令行方式或Python脚本方式,加载修改后的产线配置文件即可。
|
|
|
+
|
|
|
+## 5. 多硬件支持
|
|
|
+PaddleX 支持英伟达 GPU、昆仑芯 XPU、昇腾 NPU 和寒武纪 MLU 等多种主流硬件设备,<b>仅需设置 `device` 参数</b>即可完成不同硬件之间的无缝切换。
|
|
|
+
|
|
|
+例如,使用文档场景信息抽取v4产线时,将运行设备从英伟达 GPU 更改为昇腾 NPU,仅需将脚本中的 `device` 修改为 npu 即可:
|
|
|
+
|
|
|
+```python
|
|
|
+from paddlex import create_pipeline
|
|
|
+pipeline = create_pipeline(
|
|
|
+ pipeline="PP-ChatOCRv4-doc",
|
|
|
+ device="npu:0" # gpu:0 --> npu:0
|
|
|
+ )
|
|
|
+```
|
|
|
+若您想在更多种类的硬件上使用通用文档场景信息抽取v4产线,请参考[PaddleX多硬件使用指南](../../../other_devices_support/multi_devices_use_guide.md)。
|