|
@@ -7,13 +7,14 @@ comments: true
|
|
|
## 1. 通用表格识别产线介绍
|
|
## 1. 通用表格识别产线介绍
|
|
|
表格识别是一种自动从文档或图像中识别和提取表格内容及其结构的技术,广泛应用于数据录入、信息检索和文档分析等领域。通过使用计算机视觉和机器学习算法,表格识别能够将复杂的表格信息转换为可编辑的格式,方便用户进一步处理和分析数据。
|
|
表格识别是一种自动从文档或图像中识别和提取表格内容及其结构的技术,广泛应用于数据录入、信息检索和文档分析等领域。通过使用计算机视觉和机器学习算法,表格识别能够将复杂的表格信息转换为可编辑的格式,方便用户进一步处理和分析数据。
|
|
|
|
|
|
|
|
|
|
+通用表格识别产线用于解决表格识别任务,对图片中的表格进行识别,并以HTML格式输出。本产线集成了业界知名的 SLANet 和 SLANet_plus 表格识别模型。基于本产线,可实现对表格的精准预测,使用场景覆盖通用、制造、金融、交通等各个领域。本产线同时提供了灵活的服务化部署方式,支持在多种硬件上使用多种编程语言调用。不仅如此,本产线也提供了二次开发的能力,您可以基于本产线在您自己的数据集上训练调优,训练后的模型也可以无缝集成。
|
|
|
|
|
+
|
|
|
<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/table_recognition/01.png">
|
|
<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/table_recognition/01.png">
|
|
|
|
|
|
|
|
-<b>通用</b><b>表格识别</b><b>产线中包含表格结构识别模块、版面区域分析模块、文本检测模块和文本识别模块</b>。
|
|
|
|
|
|
|
+<b>通用</b><b>表格识别</b><b>产线中包含必选的表格结构识别模块、文本检测模块和文本识别模块,以及可选的版面区域检测模块、文档图像方向分类模块和文本图像矫正模块</b>。
|
|
|
|
|
|
|
|
-<b>如您更考虑模型精度,请选择精度较高的模型,如您更考虑模型推理速度,请选择推理速度较快的模型,如您更考虑模型存储大小,请选择存储大小较小的模型</b>。
|
|
|
|
|
|
|
+<b>如果您更注重模型的精度,请选择精度较高的模型;如果您更在意模型的推理速度,请选择推理速度较快的模型;如果您关注模型的存储大小,请选择存储体积较小的模型。</b>
|
|
|
|
|
|
|
|
-<details><summary> 👉模型列表详情</summary>
|
|
|
|
|
|
|
|
|
|
<p><b>表格识别模块模型:</b></p>
|
|
<p><b>表格识别模块模型:</b></p>
|
|
|
<table>
|
|
<table>
|
|
@@ -41,9 +42,113 @@ comments: true
|
|
|
<td>6.9 M</td>
|
|
<td>6.9 M</td>
|
|
|
</tr>
|
|
</tr>
|
|
|
</table>
|
|
</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>注:以上精度指标测量PaddleX 内部自建英文表格识别数据集。所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
-<p><b>版面区域分析模块模型:</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.0b2/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.0b2/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.0b2/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.0b2/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.0b2/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.0b2/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>
|
|
<table>
|
|
|
<thead>
|
|
<thead>
|
|
|
<tr>
|
|
<tr>
|
|
@@ -122,75 +227,66 @@ comments: true
|
|
|
</tr>
|
|
</tr>
|
|
|
</tbody>
|
|
</tbody>
|
|
|
</table>
|
|
</table>
|
|
|
-<p><b>注:以上精度指标的评估集是 PaddleX 自建的版面区域分析数据集,包含 1w 张图片。以上所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
|
|
|
|
|
-<p><b>文本检测模块模型:</b></p>
|
|
|
|
|
|
|
+<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>
|
|
<table>
|
|
|
<thead>
|
|
<thead>
|
|
|
<tr>
|
|
<tr>
|
|
|
<th>模型</th><th>模型下载链接</th>
|
|
<th>模型</th><th>模型下载链接</th>
|
|
|
-<th>检测Hmean(%)</th>
|
|
|
|
|
-<th>GPU推理耗时(ms)</th>
|
|
|
|
|
-<th>CPU推理耗时(ms)</th>
|
|
|
|
|
|
|
+<th>MS-SSIM (%)</th>
|
|
|
<th>模型存储大小(M)</th>
|
|
<th>模型存储大小(M)</th>
|
|
|
|
|
+<th>介绍</th>
|
|
|
</tr>
|
|
</tr>
|
|
|
</thead>
|
|
</thead>
|
|
|
<tbody>
|
|
<tbody>
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>PP-OCRv4_mobile_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/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.2 M</td>
|
|
|
|
|
-</tr>
|
|
|
|
|
-<tr>
|
|
|
|
|
-<td>PP-OCRv4_server_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/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>100.1M</td>
|
|
|
|
|
|
|
+<td>UVDoc</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/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>
|
|
</tr>
|
|
|
</tbody>
|
|
</tbody>
|
|
|
</table>
|
|
</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>
|
|
|
|
|
|
|
+<p><b>模型的精度指标测量自 <a href="https://www3.cs.stonybrook.edu/~cvl/docunet.html">DocUNet benchmark</a>。</b></p>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+<p><b>文档图像方向分类模块模型(可选):</b></p>
|
|
|
<table>
|
|
<table>
|
|
|
<thead>
|
|
<thead>
|
|
|
<tr>
|
|
<tr>
|
|
|
<th>模型</th><th>模型下载链接</th>
|
|
<th>模型</th><th>模型下载链接</th>
|
|
|
-<th>识别Avg Accuracy(%)</th>
|
|
|
|
|
|
|
+<th>Top-1 Acc(%)</th>
|
|
|
<th>GPU推理耗时(ms)</th>
|
|
<th>GPU推理耗时(ms)</th>
|
|
|
-<th>CPU推理耗时(ms)</th>
|
|
|
|
|
|
|
+<th>CPU推理耗时 (ms)</th>
|
|
|
<th>模型存储大小(M)</th>
|
|
<th>模型存储大小(M)</th>
|
|
|
|
|
+<th>介绍</th>
|
|
|
</tr>
|
|
</tr>
|
|
|
</thead>
|
|
</thead>
|
|
|
<tbody>
|
|
<tbody>
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>PP-OCRv4_mobile_rec</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/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>
|
|
|
|
|
-</tr>
|
|
|
|
|
-<tr>
|
|
|
|
|
-<td>PP-OCRv4_server_rec</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/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>
|
|
|
|
|
|
|
+<td>PP-LCNet_x1_0_doc_ori</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/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>
|
|
</tr>
|
|
|
</tbody>
|
|
</tbody>
|
|
|
</table>
|
|
</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></details>
|
|
|
|
|
|
|
+<p><b>注:以上精度指标的评估集是自建的数据集,覆盖证件和文档等多个场景,包含 1000 张图片。GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为 8,精度类型为 FP32。</b></p>
|
|
|
|
|
+
|
|
|
|
|
|
|
|
## 2. 快速开始
|
|
## 2. 快速开始
|
|
|
-PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可以在线体验通用图像分类产线的效果,也可以在本地使用命令行或 Python 体验通用图像分类产线的效果。
|
|
|
|
|
|
|
+PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可以在星河社区在线体验通用表格识别产线的效果,也可以在本地使用命令行或 Python 体验通用表格识别产线的效果。
|
|
|
|
|
|
|
|
### 2.1 在线体验
|
|
### 2.1 在线体验
|
|
|
您可以[在线体验](https://aistudio.baidu.com/community/app/91661/webUI)通用表格识别产线的效果,用官方提供的 demo 图片进行识别,例如:
|
|
您可以[在线体验](https://aistudio.baidu.com/community/app/91661/webUI)通用表格识别产线的效果,用官方提供的 demo 图片进行识别,例如:
|
|
|
|
|
|
|
|
<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/table_recognition/02.png">
|
|
<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/table_recognition/02.png">
|
|
|
|
|
|
|
|
-如果您对产线运行的效果满意,可以直接对产线进行集成部署,如果不满意,您也可以利用私有数据<b>对产线中的模型进行在线微调</b>。
|
|
|
|
|
|
|
+如果您对产线运行的效果满意,可以直接进行集成部署。您可以选择从云端下载部署包,也可以参考[2.2节本地体验](#22-本地体验)中的方法进行本地部署。如果对效果不满意,您可以利用私有数据<b>对产线中的模型进行微调训练</b>。如果您具备本地训练的硬件资源,可以直接在本地开展训练;如果没有,星河零代码平台提供了一键式训练服务,无需编写代码,只需上传数据后,即可一键启动训练任务。
|
|
|
|
|
|
|
|
### 2.2 本地体验
|
|
### 2.2 本地体验
|
|
|
在本地使用通用表格识别产线前,请确保您已经按照[PaddleX本地安装教程](../../../installation/installation.md)完成了PaddleX的wheel包安装。
|
|
在本地使用通用表格识别产线前,请确保您已经按照[PaddleX本地安装教程](../../../installation/installation.md)完成了PaddleX的wheel包安装。
|
|
@@ -199,117 +295,181 @@ PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可
|
|
|
一行命令即可快速体验表格识别产线效果,使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg),并将 `--input` 替换为本地路径,进行预测
|
|
一行命令即可快速体验表格识别产线效果,使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg),并将 `--input` 替换为本地路径,进行预测
|
|
|
|
|
|
|
|
```bash
|
|
```bash
|
|
|
-paddlex --pipeline table_recognition --input table_recognition.jpg --device gpu:0
|
|
|
|
|
|
|
+paddlex --pipeline table_recognition \
|
|
|
|
|
+ --input table_recognition.jpg \
|
|
|
|
|
+ --save_path ./output \
|
|
|
|
|
+ --device gpu:0
|
|
|
```
|
|
```
|
|
|
-参数说明:
|
|
|
|
|
|
|
|
|
|
-```
|
|
|
|
|
---pipeline:产线名称,此处为表格识别产线
|
|
|
|
|
---input:待处理的输入图片的本地路径或URL
|
|
|
|
|
---device 使用的GPU序号(例如gpu:0表示使用第0块GPU,gpu:1,2表示使用第1、2块GPU),也可选择使用CPU(--device cpu)
|
|
|
|
|
-```
|
|
|
|
|
|
|
+相关的参数说明可以参考[2.2.2 Python脚本方式集成](#222-python脚本方式集成)中的参数说明。
|
|
|
|
|
|
|
|
-在执行上述 Python 脚本时,加载的是默认的表格识别产线配置文件,若您需要自定义配置文件,可执行如下命令获取:
|
|
|
|
|
-
|
|
|
|
|
-<details><summary> 👉点击展开</summary>
|
|
|
|
|
-
|
|
|
|
|
-<pre><code>paddlex --get_pipeline_config table_recognition
|
|
|
|
|
-</code></pre>
|
|
|
|
|
-<p>执行后,表格识别产线配置文件将被保存在当前路径。若您希望自定义保存位置,可执行如下命令(假设自定义保存位置为 <code>./my_path</code> ):</p>
|
|
|
|
|
-<pre><code>paddlex --get_pipeline_config table_recognition --save_path ./my_path
|
|
|
|
|
-</code></pre>
|
|
|
|
|
-<p>获取产线配置文件后,可将 <code>--pipeline</code> 替换为配置文件保存路径,即可使配置文件生效。例如,若配置文件保存路径为 <code>./table_recognition.yaml</code>,只需执行:</p>
|
|
|
|
|
-<pre><code class="language-bash">paddlex --pipeline ./table_recognition.yaml --input table_recognition.jpg --device gpu:0
|
|
|
|
|
-</code></pre>
|
|
|
|
|
-<p>其中,<code>--model</code>、<code>--device</code> 等参数无需指定,将使用配置文件中的参数。若依然指定了参数,将以指定的参数为准。</p></details>
|
|
|
|
|
-
|
|
|
|
|
-运行后,得到的结果为:
|
|
|
|
|
-
|
|
|
|
|
-<details><summary> 👉点击展开</summary>
|
|
|
|
|
-
|
|
|
|
|
-<pre><code>{'input_path': 'table_recognition.jpg', 'layout_result': {'input_path': 'table_recognition.jpg', 'boxes': [{'cls_id': 3, 'label': 'Table', 'score': 0.6014542579650879, 'coordinate': [0, 21, 551, 118]}]}, 'ocr_result': {'dt_polys': [array([[37., 40.],
|
|
|
|
|
- [75., 40.],
|
|
|
|
|
- [75., 60.],
|
|
|
|
|
- [37., 60.]], dtype=float32), array([[123., 37.],
|
|
|
|
|
- [200., 37.],
|
|
|
|
|
- [200., 59.],
|
|
|
|
|
- [123., 59.]], dtype=float32), array([[227., 37.],
|
|
|
|
|
- [391., 37.],
|
|
|
|
|
- [391., 58.],
|
|
|
|
|
- [227., 58.]], dtype=float32), array([[416., 36.],
|
|
|
|
|
- [535., 38.],
|
|
|
|
|
- [535., 61.],
|
|
|
|
|
- [415., 58.]], dtype=float32), array([[35., 73.],
|
|
|
|
|
- [78., 73.],
|
|
|
|
|
- [78., 92.],
|
|
|
|
|
- [35., 92.]], dtype=float32), array([[287., 73.],
|
|
|
|
|
- [328., 73.],
|
|
|
|
|
- [328., 92.],
|
|
|
|
|
- [287., 92.]], dtype=float32), array([[453., 72.],
|
|
|
|
|
- [495., 72.],
|
|
|
|
|
- [495., 94.],
|
|
|
|
|
- [453., 94.]], dtype=float32), array([[ 17., 103.],
|
|
|
|
|
- [ 94., 103.],
|
|
|
|
|
- [ 94., 118.],
|
|
|
|
|
- [ 17., 118.]], dtype=float32), array([[145., 104.],
|
|
|
|
|
- [178., 104.],
|
|
|
|
|
- [178., 118.],
|
|
|
|
|
- [145., 118.]], dtype=float32), array([[277., 104.],
|
|
|
|
|
- [337., 102.],
|
|
|
|
|
- [338., 118.],
|
|
|
|
|
- [278., 118.]], dtype=float32), array([[446., 102.],
|
|
|
|
|
- [504., 104.],
|
|
|
|
|
- [503., 118.],
|
|
|
|
|
- [445., 118.]], dtype=float32)], 'rec_text': ['Dres', '连续工作3', '取出来放在网上,没想', '江、整江等八大', 'Abstr', 'rSrivi', '$709.', 'cludingGiv', '2.72', 'Ingcubic', '$744.78'], 'rec_score': [0.9934158325195312, 0.9990204572677612, 0.9967061877250671, 0.9375461935997009, 0.9947397112846375, 0.9972746968269348, 0.9904290437698364, 0.973427414894104, 0.9983080625534058, 0.993423342704773, 0.9964120984077454], 'input_path': 'table_recognition.jpg'}, 'table_result': [{'input_path': 'table_recognition.jpg', 'layout_bbox': [0, 21, 551, 118], 'bbox': array([[ 4.395736 , 25.238262 , 113.31014 , 25.316246 , 115.454315 ,
|
|
|
|
|
- 71.8867 , 3.7177477, 71.7937 ],
|
|
|
|
|
- [110.727455 , 25.94007 , 210.07187 , 26.028755 , 209.66394 ,
|
|
|
|
|
- 65.96484 , 109.59861 , 66.09809 ],
|
|
|
|
|
- [214.45381 , 26.027939 , 407.95276 , 26.112846 , 409.6684 ,
|
|
|
|
|
- 66.91336 , 215.27292 , 67.002014 ],
|
|
|
|
|
- [402.81863 , 26.123789 , 549.03656 , 26.231564 , 549.19995 ,
|
|
|
|
|
- 66.88339 , 404.48068 , 66.74034 ],
|
|
|
|
|
- [ 2.4458022, 64.68588 , 102.7665 , 65.10228 , 105.79447 ,
|
|
|
|
|
- 96.051254 , 2.5367072, 95.35514 ],
|
|
|
|
|
- [108.85877 , 65.80549 , 211.70216 , 66.02091 , 210.79245 ,
|
|
|
|
|
- 94.75581 , 107.59308 , 94.42664 ],
|
|
|
|
|
- [217.05621 , 64.98496 , 407.76328 , 65.133484 , 406.8436 ,
|
|
|
|
|
- 96.00133 , 214.67896 , 95.87226 ],
|
|
|
|
|
- [401.73572 , 64.60494 , 547.9967 , 64.73921 , 548.19135 ,
|
|
|
|
|
- 96.09901 , 402.26733 , 95.95529 ],
|
|
|
|
|
- [ 2.4882016, 93.589554 , 107.01325 , 93.67592 , 107.8446 ,
|
|
|
|
|
- 120.13259 , 2.508764 , 119.85027 ],
|
|
|
|
|
- [110.773125 , 93.98633 , 213.354 , 94.08046 , 212.46033 ,
|
|
|
|
|
- 120.80207 , 109.29008 , 120.613045 ],
|
|
|
|
|
- [216.08781 , 94.19984 , 405.843 , 94.28341 , 405.9974 ,
|
|
|
|
|
- 121.33152 , 215.10301 , 121.299034 ],
|
|
|
|
|
- [403.92212 , 94.44883 , 548.30963 , 94.54982 , 548.4949 ,
|
|
|
|
|
- 122.610176 , 404.53433 , 122.49881 ]], dtype=float32), 'img_idx': 0, 'html': '<html><body><table><tr><td>Dres</td><td>连续工作3</td><td>取出来放在网上,没想</td><td>江、整江等八大</td></tr><tr><td>Abstr</td><td></td><td>rSrivi</td><td>$709.</td></tr><tr><td>cludingGiv</td><td>2.72</td><td>Ingcubic</td><td>$744.78</td></tr></table></body></html>'}]}
|
|
|
|
|
-</code></pre></details>
|
|
|
|
|
|
|
+运行后,会将结果打印到终端上,结果如下:
|
|
|
|
|
|
|
|
|
|
+```bash
|
|
|
|
|
+{'res': {'input_path': 'table_recognition.jpg', 'model_settings': {'use_doc_preprocessor': True, 'use_layout_detection': True, 'use_ocr_model': True}, 'doc_preprocessor_res': {'input_path': '0.jpg', 'model_settings': {'use_doc_orientation_classify': True, 'use_doc_unwarping': True}, 'angle': 0}, 'layout_det_res': {'input_path': None, 'boxes': [{'cls_id': 0, 'label': 'Table', 'score': 0.9196816086769104, 'coordinate': [0, 8.614925, 550.9877, 132]}]}, 'overall_ocr_res': {'input_path': '0.jpg', 'model_settings': {'use_doc_preprocessor': False, 'use_textline_orientation': False}, 'dt_polys': [array([[232, 0],
|
|
|
|
|
+ [318, 1],
|
|
|
|
|
+ [318, 24],
|
|
|
|
|
+ [232, 21]], dtype=int16), array([[32, 38],
|
|
|
|
|
+ [67, 38],
|
|
|
|
|
+ [67, 55],
|
|
|
|
|
+ [32, 55]], dtype=int16), array([[119, 34],
|
|
|
|
|
+ [196, 34],
|
|
|
|
|
+ [196, 57],
|
|
|
|
|
+ [119, 57]], dtype=int16), array([[222, 29],
|
|
|
|
|
+ [396, 31],
|
|
|
|
|
+ [396, 60],
|
|
|
|
|
+ [222, 58]], dtype=int16), array([[420, 30],
|
|
|
|
|
+ [542, 32],
|
|
|
|
|
+ [542, 61],
|
|
|
|
|
+ [419, 59]], dtype=int16), array([[29, 71],
|
|
|
|
|
+ [72, 71],
|
|
|
|
|
+ [72, 92],
|
|
|
|
|
+ [29, 92]], dtype=int16), array([[287, 72],
|
|
|
|
|
+ [329, 72],
|
|
|
|
|
+ [329, 93],
|
|
|
|
|
+ [287, 93]], dtype=int16), array([[458, 68],
|
|
|
|
|
+ [501, 71],
|
|
|
|
|
+ [499, 94],
|
|
|
|
|
+ [456, 91]], dtype=int16), array([[ 9, 101],
|
|
|
|
|
+ [ 89, 103],
|
|
|
|
|
+ [ 89, 130],
|
|
|
|
|
+ [ 8, 128]], dtype=int16), array([[139, 105],
|
|
|
|
|
+ [172, 105],
|
|
|
|
|
+ [172, 126],
|
|
|
|
|
+ [139, 126]], dtype=int16), array([[274, 103],
|
|
|
|
|
+ [339, 101],
|
|
|
|
|
+ [340, 128],
|
|
|
|
|
+ [275, 130]], dtype=int16), array([[451, 103],
|
|
|
|
|
+ [508, 103],
|
|
|
|
|
+ [508, 126],
|
|
|
|
|
+ [451, 126]], dtype=int16)], 'text_det_params': {'limit_side_len': 960, 'limit_type': 'max', 'thresh': 0.3, 'box_thresh': 0.6, 'unclip_ratio': 2.0}, 'text_type': 'general', 'textline_orientation_angles': [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 'text_rec_score_thresh': 0, 'rec_texts': ['CRuncover', 'Dres', '连续工作3', '取出来放在网上,没想', '江、江等八大', 'Abstr', 'rSrivi', '$709.', 'cludingGiv', '2.72', 'Ingcubic', '$744.78'], 'rec_scores': [0.9943075180053711, 0.9951075315475464, 0.9907732009887695, 0.9975494146347046, 0.9974043369293213, 0.9983242750167847, 0.991967499256134, 0.9898287653923035, 0.9961177110671997, 0.9975040555000305, 0.9986456632614136, 0.9987970590591431], 'rec_polys': [array([[232, 0],
|
|
|
|
|
+ [318, 1],
|
|
|
|
|
+ [318, 24],
|
|
|
|
|
+ [232, 21]], dtype=int16), array([[32, 38],
|
|
|
|
|
+ [67, 38],
|
|
|
|
|
+ [67, 55],
|
|
|
|
|
+ [32, 55]], dtype=int16), array([[119, 34],
|
|
|
|
|
+ [196, 34],
|
|
|
|
|
+ [196, 57],
|
|
|
|
|
+ [119, 57]], dtype=int16), array([[222, 29],
|
|
|
|
|
+ [396, 31],
|
|
|
|
|
+ [396, 60],
|
|
|
|
|
+ [222, 58]], dtype=int16), array([[420, 30],
|
|
|
|
|
+ [542, 32],
|
|
|
|
|
+ [542, 61],
|
|
|
|
|
+ [419, 59]], dtype=int16), array([[29, 71],
|
|
|
|
|
+ [72, 71],
|
|
|
|
|
+ [72, 92],
|
|
|
|
|
+ [29, 92]], dtype=int16), array([[287, 72],
|
|
|
|
|
+ [329, 72],
|
|
|
|
|
+ [329, 93],
|
|
|
|
|
+ [287, 93]], dtype=int16), array([[458, 68],
|
|
|
|
|
+ [501, 71],
|
|
|
|
|
+ [499, 94],
|
|
|
|
|
+ [456, 91]], dtype=int16), array([[ 9, 101],
|
|
|
|
|
+ [ 89, 103],
|
|
|
|
|
+ [ 89, 130],
|
|
|
|
|
+ [ 8, 128]], dtype=int16), array([[139, 105],
|
|
|
|
|
+ [172, 105],
|
|
|
|
|
+ [172, 126],
|
|
|
|
|
+ [139, 126]], dtype=int16), array([[274, 103],
|
|
|
|
|
+ [339, 101],
|
|
|
|
|
+ [340, 128],
|
|
|
|
|
+ [275, 130]], dtype=int16), array([[451, 103],
|
|
|
|
|
+ [508, 103],
|
|
|
|
|
+ [508, 126],
|
|
|
|
|
+ [451, 126]], dtype=int16)], 'rec_boxes': array([[232, 0, 318, 24],
|
|
|
|
|
+ [ 32, 38, 67, 55],
|
|
|
|
|
+ [119, 34, 196, 57],
|
|
|
|
|
+ [222, 29, 396, 60],
|
|
|
|
|
+ [419, 30, 542, 61],
|
|
|
|
|
+ [ 29, 71, 72, 92],
|
|
|
|
|
+ [287, 72, 329, 93],
|
|
|
|
|
+ [456, 68, 501, 94],
|
|
|
|
|
+ [ 8, 101, 89, 130],
|
|
|
|
|
+ [139, 105, 172, 126],
|
|
|
|
|
+ [274, 101, 340, 130],
|
|
|
|
|
+ [451, 103, 508, 126]], dtype=int16)}, 'table_res_list': [{'cell_box_list': array([[ 8. , 9.61492538, 532. , 26.61492538],
|
|
|
|
|
+ [ 3. , 27.61492538, 104. , 65.61492538],
|
|
|
|
|
+ [109. , 28.61492538, 215. , 66.61492538],
|
|
|
|
|
+ [219. , 28.61492538, 396. , 64.61492538],
|
|
|
|
|
+ [396. , 29.61492538, 546. , 66.61492538],
|
|
|
|
|
+ [ 1. , 65.61492538, 110. , 93.61492538],
|
|
|
|
|
+ [111. , 65.61492538, 215. , 94.61492538],
|
|
|
|
|
+ [220. , 66.61492538, 397. , 94.61492538],
|
|
|
|
|
+ [398. , 67.61492538, 544. , 94.61492538],
|
|
|
|
|
+ [ 2. , 98.61492538, 111. , 131.61492538],
|
|
|
|
|
+ [113. , 98.61492538, 216. , 131.61492538],
|
|
|
|
|
+ [219. , 98.61492538, 400. , 131.61492538],
|
|
|
|
|
+ [403. , 99.61492538, 545. , 130.61492538]]), 'pred_html': '<html><body><table><tr><td colspan="4">CRuncover</td></tr><tr><td>Dres</td><td>连续工作3</td><td>取出来放在网上,没想</td><td>江、江等八大</td></tr><tr><td>Abstr</td><td></td><td>rSrivi</td><td>$709.</td></tr><tr><td>cludingGiv</td><td>2.72</td><td>Ingcubic</td><td>$744.78</td></tr></table></body></html>', 'table_ocr_pred': {'rec_polys': [array([[232, 0],
|
|
|
|
|
+ [318, 1],
|
|
|
|
|
+ [318, 24],
|
|
|
|
|
+ [232, 21]], dtype=int16), array([[32, 38],
|
|
|
|
|
+ [67, 38],
|
|
|
|
|
+ [67, 55],
|
|
|
|
|
+ [32, 55]], dtype=int16), array([[119, 34],
|
|
|
|
|
+ [196, 34],
|
|
|
|
|
+ [196, 57],
|
|
|
|
|
+ [119, 57]], dtype=int16), array([[222, 29],
|
|
|
|
|
+ [396, 31],
|
|
|
|
|
+ [396, 60],
|
|
|
|
|
+ [222, 58]], dtype=int16), array([[420, 30],
|
|
|
|
|
+ [542, 32],
|
|
|
|
|
+ [542, 61],
|
|
|
|
|
+ [419, 59]], dtype=int16), array([[29, 71],
|
|
|
|
|
+ [72, 71],
|
|
|
|
|
+ [72, 92],
|
|
|
|
|
+ [29, 92]], dtype=int16), array([[287, 72],
|
|
|
|
|
+ [329, 72],
|
|
|
|
|
+ [329, 93],
|
|
|
|
|
+ [287, 93]], dtype=int16), array([[458, 68],
|
|
|
|
|
+ [501, 71],
|
|
|
|
|
+ [499, 94],
|
|
|
|
|
+ [456, 91]], dtype=int16), array([[ 9, 101],
|
|
|
|
|
+ [ 89, 103],
|
|
|
|
|
+ [ 89, 130],
|
|
|
|
|
+ [ 8, 128]], dtype=int16), array([[139, 105],
|
|
|
|
|
+ [172, 105],
|
|
|
|
|
+ [172, 126],
|
|
|
|
|
+ [139, 126]], dtype=int16), array([[274, 103],
|
|
|
|
|
+ [339, 101],
|
|
|
|
|
+ [340, 128],
|
|
|
|
|
+ [275, 130]], dtype=int16), array([[451, 103],
|
|
|
|
|
+ [508, 103],
|
|
|
|
|
+ [508, 126],
|
|
|
|
|
+ [451, 126]], dtype=int16)], 'rec_texts': ['CRuncover', 'Dres', '连续工作3', '取出来放在网上,没想', '江、江等八大', 'Abstr', 'rSrivi', '$709.', 'cludingGiv', '2.72', 'Ingcubic', '$744.78'], 'rec_scores': [0.9943075180053711, 0.9951075315475464, 0.9907732009887695, 0.9975494146347046, 0.9974043369293213, 0.9983242750167847, 0.991967499256134, 0.9898287653923035, 0.9961177110671997, 0.9975040555000305, 0.9986456632614136, 0.9987970590591431], 'rec_boxes': [array([232, 0, 318, 24], dtype=int16), array([32, 38, 67, 55], dtype=int16), array([119, 34, 196, 57], dtype=int16), array([222, 29, 396, 60], dtype=int16), array([419, 30, 542, 61], dtype=int16), array([29, 71, 72, 92], dtype=int16), array([287, 72, 329, 93], dtype=int16), array([456, 68, 501, 94], dtype=int16), array([ 8, 101, 89, 130], dtype=int16), array([139, 105, 172, 126], dtype=int16), array([274, 101, 340, 130], dtype=int16), array([451, 103, 508, 126], dtype=int16)]}}]}}
|
|
|
|
|
+```
|
|
|
|
|
+运行结果参数说明可以参考[2.2.2 Python脚本方式集成](#222-python脚本方式集成)中的结果解释。
|
|
|
|
|
+
|
|
|
|
|
+可视化结果保存在`save_path`下,其中表格识别的可视化结果如下:
|
|
|
<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/table_recognition/03.png">
|
|
<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/table_recognition/03.png">
|
|
|
|
|
|
|
|
-可视化图片默认不进行保存,您可以通过 `--save_path` 自定义保存路径,随后所有结果将被保存在指定路径下。
|
|
|
|
|
|
|
|
|
|
### 2.2 Python脚本方式集成
|
|
### 2.2 Python脚本方式集成
|
|
|
-几行代码即可完成产线的快速推理,以通用表格识别产线为例:
|
|
|
|
|
|
|
+* 上述命令行是为了快速体验查看效果,一般来说,在项目中,往往需要通过代码集成,您可以通过几行代码即可完成产线的快速推理,推理代码如下:
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
from paddlex import create_pipeline
|
|
from paddlex import create_pipeline
|
|
|
|
|
|
|
|
-pipeline = create_pipeline(pipeline="table_recognition")
|
|
|
|
|
|
|
+pipeline = create_pipeline(pipeline_name="table_recognition")
|
|
|
|
|
+
|
|
|
|
|
+output = pipeline.predict(
|
|
|
|
|
+ input="table_recognition.jpg",
|
|
|
|
|
+ use_doc_orientation_classify=False,
|
|
|
|
|
+ use_doc_unwarping=False,
|
|
|
|
|
+)
|
|
|
|
|
|
|
|
-output = pipeline.predict("table_recognition.jpg")
|
|
|
|
|
for res in output:
|
|
for res in output:
|
|
|
- res.print() ## 打印预测的结构化输出
|
|
|
|
|
- res.save_to_img("./output/") ## 保存img格式结果
|
|
|
|
|
- res.save_to_xlsx("./output/") ## 保存表格格式结果
|
|
|
|
|
- res.save_to_html("./output/") ## 保存html结果
|
|
|
|
|
|
|
+ res.print()
|
|
|
|
|
+ res.save_to_img("./output/")
|
|
|
|
|
+ res.save_to_xlsx("./output/")
|
|
|
|
|
+ res.save_to_html("./output/")
|
|
|
|
|
+ res.save_to_json("./output/")
|
|
|
```
|
|
```
|
|
|
-得到的结果与命令行方式相同。
|
|
|
|
|
|
|
|
|
|
在上述 Python 脚本中,执行了如下几个步骤:
|
|
在上述 Python 脚本中,执行了如下几个步骤:
|
|
|
|
|
|
|
|
-(1)实例化 `create_pipeline` 实例化产线对象:具体参数说明如下:
|
|
|
|
|
|
|
+(1)通过 `create_pipeline()` 实例化通用表格识别产线对象,具体参数说明如下:
|
|
|
|
|
|
|
|
<table>
|
|
<table>
|
|
|
<thead>
|
|
<thead>
|
|
@@ -325,13 +485,13 @@ for res in output:
|
|
|
<td><code>pipeline</code></td>
|
|
<td><code>pipeline</code></td>
|
|
|
<td>产线名称或是产线配置文件路径。如为产线名称,则必须为 PaddleX 所支持的产线。</td>
|
|
<td>产线名称或是产线配置文件路径。如为产线名称,则必须为 PaddleX 所支持的产线。</td>
|
|
|
<td><code>str</code></td>
|
|
<td><code>str</code></td>
|
|
|
-<td>无</td>
|
|
|
|
|
|
|
+<td><code>None</code></td>
|
|
|
</tr>
|
|
</tr>
|
|
|
<tr>
|
|
<tr>
|
|
|
<td><code>device</code></td>
|
|
<td><code>device</code></td>
|
|
|
-<td>产线模型推理设备。支持:“gpu”,“cpu”。</td>
|
|
|
|
|
|
|
+<td>产线推理设备。支持指定GPU具体卡号,如“gpu:0”,其他硬件具体卡号,如“npu:0”,CPU如“cpu”。</td>
|
|
|
<td><code>str</code></td>
|
|
<td><code>str</code></td>
|
|
|
-<td><code>gpu</code></td>
|
|
|
|
|
|
|
+<td><code>gpu:0</code></td>
|
|
|
</tr>
|
|
</tr>
|
|
|
<tr>
|
|
<tr>
|
|
|
<td><code>use_hpip</code></td>
|
|
<td><code>use_hpip</code></td>
|
|
@@ -341,89 +501,320 @@ for res in output:
|
|
|
</tr>
|
|
</tr>
|
|
|
</tbody>
|
|
</tbody>
|
|
|
</table>
|
|
</table>
|
|
|
-(2)调用产线对象的 `predict` 方法进行推理预测:`predict` 方法参数为`x`,用于输入待预测数据,支持多种输入方式,具体示例如下:
|
|
|
|
|
|
|
+
|
|
|
|
|
+(2)调用通用表格识别产线对象的 `predict()` 方法进行推理预测。该方法将返回一个 `generator`。以下是 `predict()` 方法的参数及其说明:
|
|
|
|
|
|
|
|
<table>
|
|
<table>
|
|
|
<thead>
|
|
<thead>
|
|
|
<tr>
|
|
<tr>
|
|
|
-<th>参数类型</th>
|
|
|
|
|
|
|
+<th>参数</th>
|
|
|
<th>参数说明</th>
|
|
<th>参数说明</th>
|
|
|
|
|
+<th>参数类型</th>
|
|
|
|
|
+<th>可选项</th>
|
|
|
|
|
+<th>默认值</th>
|
|
|
</tr>
|
|
</tr>
|
|
|
</thead>
|
|
</thead>
|
|
|
-<tbody>
|
|
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>Python Var</td>
|
|
|
|
|
-<td>支持直接传入Python变量,如numpy.ndarray表示的图像数据。</td>
|
|
|
|
|
|
|
+<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/table_recognition.jpg">示例</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>
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>str</td>
|
|
|
|
|
-<td>支持传入待预测数据文件路径,如图像文件的本地路径:<code>/root/data/img.jpg</code>。</td>
|
|
|
|
|
|
|
+<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>
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>str</td>
|
|
|
|
|
-<td>支持传入待预测数据文件URL,如图像文件的网络URL:<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg">示例</a>。</td>
|
|
|
|
|
|
|
+<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>
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>str</td>
|
|
|
|
|
-<td>支持传入本地目录,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code>。</td>
|
|
|
|
|
|
|
+<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>
|
|
|
-<tr>
|
|
|
|
|
-<td>dict</td>
|
|
|
|
|
-<td>支持传入字典类型,字典的key需与具体任务对应,如图像分类任务对应\"img\",字典的val支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code>。</td>
|
|
|
|
|
|
|
+<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>
|
|
|
-<tr>
|
|
|
|
|
-<td>list</td>
|
|
|
|
|
-<td>支持传入列表,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray],[\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code>,<code>[{\"img\": \"/root/data1\"}, {\"img\": \"/root/data2/img.jpg\"}]</code>。</td>
|
|
|
|
|
|
|
+<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>
|
|
|
|
|
+<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>
|
|
|
|
|
+<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>
|
|
|
|
|
+<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>
|
|
|
|
|
+<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>
|
|
|
-</tbody>
|
|
|
|
|
-</table>
|
|
|
|
|
-(3)调用`predict`方法获取预测结果:`predict` 方法为`generator`,因此需要通过调用获得预测结果,`predict`方法以batch为单位对数据进行预测,因此预测结果为list形式表示的一组预测结果。
|
|
|
|
|
|
|
|
|
|
-(4)对预测结果进行处理:每个样本的预测结果均为`dict`类型,且支持打印,或保存为文件,支持保存的类型与具体产线相关,如:
|
|
|
|
|
|
|
+</table>
|
|
|
|
|
|
|
|
|
|
+(3)对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为图片、保存为`xlsx`文件、保存为`HTML`文件、保存为`json`文件的操作:
|
|
|
|
|
|
|
|
<table>
|
|
<table>
|
|
|
<thead>
|
|
<thead>
|
|
|
<tr>
|
|
<tr>
|
|
|
<th>方法</th>
|
|
<th>方法</th>
|
|
|
-<th>说明</th>
|
|
|
|
|
-<th>方法参数</th>
|
|
|
|
|
|
|
+<th>方法说明</th>
|
|
|
|
|
+<th>参数</th>
|
|
|
|
|
+<th>参数类型</th>
|
|
|
|
|
+<th>参数说明</th>
|
|
|
|
|
+<th>默认值</th>
|
|
|
</tr>
|
|
</tr>
|
|
|
</thead>
|
|
</thead>
|
|
|
-<tbody>
|
|
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>save_to_img</td>
|
|
|
|
|
-<td>将结果保存为img格式的文件</td>
|
|
|
|
|
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
|
|
|
|
|
|
|
+<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>
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>save_to_html</td>
|
|
|
|
|
|
|
+<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>将结果保存为图像格式的文件</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>
|
|
|
|
|
+<tr>
|
|
|
|
|
+<td><code>save_to_html()</code></td>
|
|
|
<td>将结果保存为html格式的文件</td>
|
|
<td>将结果保存为html格式的文件</td>
|
|
|
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
|
|
|
|
|
|
|
+<td><code>save_path</code></td>
|
|
|
|
|
+<td><code>str</code></td>
|
|
|
|
|
+<td>保存的文件路径,支持目录或文件路径</td>
|
|
|
|
|
+<td>无</td>
|
|
|
</tr>
|
|
</tr>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+</table>
|
|
|
|
|
+
|
|
|
|
|
+- 调用`print()` 方法会将结果打印到终端,打印到终端的内容解释如下:
|
|
|
|
|
+
|
|
|
|
|
+ - `input_path`: `(str)` 待预测图像的输入路径
|
|
|
|
|
+
|
|
|
|
|
+ - `model_settings`: `(Dict[str, bool])` 配置产线所需的模型参数
|
|
|
|
|
+
|
|
|
|
|
+ - `use_doc_preprocessor`: `(bool)` 控制是否启用文档预处理子产线
|
|
|
|
|
+ - `doc_preprocessor_res`: `(Dict[str, Union[str, Dict[str, bool], int]])` 文档预处理子产线的输出结果。仅当`use_doc_preprocessor=True`时存在
|
|
|
|
|
+ - `input_path`: `(Union[str, None])` 图像预处理子产线接受的图像路径,当输入为`numpy.ndarray`时,保存为`None`
|
|
|
|
|
+ - `model_settings`: `(Dict)` 预处理子产线的模型配置参数
|
|
|
|
|
+ - `use_doc_orientation_classify`: `(bool)` 控制是否启用文档方向分类
|
|
|
|
|
+ - `use_doc_unwarping`: `(bool)` 控制是否启用文档扭曲矫正
|
|
|
|
|
+ - `angle`: `(int)` 文档方向分类的预测结果。启用时取值为[0,1,2,3],分别对应[0°,90°,180°,270°];未启用时为-1
|
|
|
|
|
+
|
|
|
|
|
+ - `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_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。每一行表示一个矩形框的[x_min, y_min, x_max, y_max]坐标
|
|
|
|
|
+ ,其中(x_min, y_min)为左上角坐标,(x_max, y_max)为右下角坐标
|
|
|
|
|
+
|
|
|
|
|
+- 调用`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}`,如果指定为文件,则直接保存到该文件中。(产线通常包含较多结果图片,不建议直接指定为具体的文件路径,否则多张图会被覆盖,仅保留最后一张图)
|
|
|
|
|
+- 调用`save_to_html()` 方法会将上述内容保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_img_basename}.html`,如果指定为文件,则直接保存到该文件中。在通用表格识别产线中,将会把图像中表格的HTML形式写入到指定的html文件中。
|
|
|
|
|
+- 调用`save_to_xlsx()` 方法会将上述内容保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_img_basename}.xlsx`,如果指定为文件,则直接保存到该文件中。在通用表格识别产线中,将会把图像中表格的Excel表格形式写入到指定的xlsx文件中。
|
|
|
|
|
+
|
|
|
|
|
+* 此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
|
|
|
|
|
+
|
|
|
|
|
+<table>
|
|
|
|
|
+<thead>
|
|
|
<tr>
|
|
<tr>
|
|
|
-<td>save_to_xlsx</td>
|
|
|
|
|
-<td>将结果保存为表格格式的文件</td>
|
|
|
|
|
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
|
|
|
|
|
|
|
+<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>
|
|
</tr>
|
|
|
-</tbody>
|
|
|
|
|
</table>
|
|
</table>
|
|
|
-其中,`save_to_img` 能够保存可视化结果(包括OCR结果图片、版面分析结果图片、表格结构识别结果图片), `save_to_html` 能够将表格直接保存为html文件(包括文本和表格格式),`save_to_xlsx` 能够将表格保存为Excel格式文件(包括文本和格式)。
|
|
|
|
|
|
|
|
|
|
-若您获取了配置文件,即可对表格识别产线各项配置进行自定义,只需要修改 `create_pipeline` 方法中的 `pipeline` 参数值为产线配置文件路径即可。
|
|
|
|
|
|
|
+- `json` 属性获取的预测结果为dict类型的数据,相关内容与调用 `save_to_json()` 方法保存的内容一致。
|
|
|
|
|
+- `img` 属性返回的预测结果是一个字典类型的数据。其中,键分别为 `table_res_img`、`ocr_res_img` 、`layout_res_img` 和 `preprocessed_img`,对应的值是四个 `Image.Image` 对象,按顺序分别为:表格识别结果的可视化图像、OCR 结果的可视化图像、版面区域检测结果的可视化图像、图像预处理的可视化图像。如果没有使用某个子模块,则字典中不包含对应的结果图像。
|
|
|
|
|
+
|
|
|
|
|
+此外,您可以获取通用表格识别产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
|
|
|
|
|
+
|
|
|
|
|
+```
|
|
|
|
|
+paddlex --get_pipeline_config table_recognition --save_path ./my_path
|
|
|
|
|
+```
|
|
|
|
|
|
|
|
-例如,若您的配置文件保存在 `./my_path/table_recognition.yaml` ,则只需执行:
|
|
|
|
|
|
|
+若您获取了配置文件,即可对通用表格识别产线各项配置进行自定义,只需要修改 `create_pipeline` 方法中的 `pipeline` 参数值为产线配置文件路径即可。示例如下:
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
from paddlex import create_pipeline
|
|
from paddlex import create_pipeline
|
|
|
-pipeline = create_pipeline(pipeline="./my_path/table_recognition.yaml")
|
|
|
|
|
-output = pipeline.predict("table_recognition.jpg")
|
|
|
|
|
|
|
+
|
|
|
|
|
+pipeline = create_pipeline(pipeline_name="./my_path/table_recognition.yaml")
|
|
|
|
|
+
|
|
|
|
|
+output = pipeline.predict(
|
|
|
|
|
+ input="table_recognition.jpg",
|
|
|
|
|
+ use_doc_orientation_classify=False,
|
|
|
|
|
+ use_doc_unwarping=False,
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
for res in output:
|
|
for res in output:
|
|
|
- res.print() ## 打印预测的结构化输出
|
|
|
|
|
- res.save_to_img("./output/") ## 保存img格式结果
|
|
|
|
|
- res.save_to_xlsx("./output/") ## 保存表格格式结果
|
|
|
|
|
- res.save_to_html("./output/") ## 保存html结果
|
|
|
|
|
|
|
+ res.print()
|
|
|
|
|
+ res.save_to_img("./output/")
|
|
|
|
|
+ res.save_to_xlsx("./output/")
|
|
|
|
|
+ res.save_to_html("./output/")
|
|
|
|
|
+ res.save_to_json("./output/")
|
|
|
|
|
+
|
|
|
```
|
|
```
|
|
|
|
|
+
|
|
|
|
|
+<b>注:</b> 配置文件中的参数为产线初始化参数,如果希望更改通用通用表格识别产线初始化参数,可以直接修改配置文件中的参数,并加载配置文件进行预测。同时,CLI 预测也支持传入配置文件,`--pipeline` 指定配置文件的路径即可。
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
## 3. 开发集成/部署
|
|
## 3. 开发集成/部署
|
|
|
如果产线可以达到您对产线推理速度和精度的要求,您可以直接进行开发集成/部署。
|
|
如果产线可以达到您对产线推理速度和精度的要求,您可以直接进行开发集成/部署。
|
|
|
|
|
|
|
@@ -655,46 +1046,117 @@ for i, res in enumerate(result["tableRecResults"]):
|
|
|
如果通用表格识别产线提供的默认模型权重在您的场景中,精度或速度不满意,您可以尝试利用<b>您自己拥有的特定领域或应用场景的数据</b>对现有模型进行进一步的<b>微调</b>,以提升通用表格识别产线的在您的场景中的识别效果。
|
|
如果通用表格识别产线提供的默认模型权重在您的场景中,精度或速度不满意,您可以尝试利用<b>您自己拥有的特定领域或应用场景的数据</b>对现有模型进行进一步的<b>微调</b>,以提升通用表格识别产线的在您的场景中的识别效果。
|
|
|
|
|
|
|
|
### 4.1 模型微调
|
|
### 4.1 模型微调
|
|
|
-由于通用表格识别产线包含四个模块,模型产线的效果不及预期可能来自于其中任何一个模块。
|
|
|
|
|
|
|
+由于通用表格识别产线包含若干模块,模型产线的效果如果不及预期,可能来自于其中任何一个模块。您可以对识别效果差的图片进行分析,进而确定是哪个模块存在问题,并参考以下表格中对应的微调教程链接进行模型微调。
|
|
|
|
|
|
|
|
-您可以对识别效果差的图片进行分析,参考如下规则进行分析和模型微调:
|
|
|
|
|
-
|
|
|
|
|
-* 检测到的表格结构错误(如行列识别错误、单元格位置错误),那么可能是表格结构识别模块存在不足,您需要参考[表格结构识别模块开发教程](../../../module_usage/tutorials/ocr_modules/table_structure_recognition.md)中的[二次开发](../../../module_usage/tutorials/ocr_modules/table_structure_recognition.md#四二次开发)章节,使用您的私有数据集对表格结构识别模型进行微调。
|
|
|
|
|
-* 表格区域在整体版面中定位错误,那么可能是版面区域定位模块存在不足,您需要参考[版面区域检测模块开发教程](../../../module_usage/tutorials/ocr_modules/layout_detection.md)中的[二次开发](../../../module_usage/tutorials/ocr_modules/layout_detection.md#四二次开发)章节,使用您的私有数据集对版面区域定位模型进行微调。
|
|
|
|
|
-* 有较多的文本未被检测出来(即文本漏检现象),那么可能是文本检测模型存在不足,您需要参考[文本检测模块开发教程](../../../module_usage/tutorials/ocr_modules/text_recognition.md)中的[二次开发](../../../module_usage/tutorials/ocr_modules/text_recognition.md#四二次开发)章节,使用您的私有数据集对文本检测模型进行微调。
|
|
|
|
|
-* 已检测到的文本中出现较多的识别错误(即识别出的文本内容与实际文本内容不符),这表明文本识别模型需要进一步改进,您需要参考[文本识别模块开发教程](../../../module_usage/tutorials/ocr_modules/table_structure_recognition.md)中的[二次开发](../../../module_usage/tutorials/ocr_modules/table_structure_recognition.md#四二次开发)章节对文本识别模型进行微调。
|
|
|
|
|
|
|
+<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/table_structure_recognition.md">链接</a></td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ <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/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/doc_img_orientation_classification.md">链接</a></td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <td>图像扭曲矫正不准</td>
|
|
|
|
|
+ <td>文本图像矫正模块</td>
|
|
|
|
|
+ <td>暂不支持微调</td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ </tbody>
|
|
|
|
|
+</table>
|
|
|
|
|
|
|
|
### 4.2 模型应用
|
|
### 4.2 模型应用
|
|
|
当您使用私有数据集完成微调训练后,可获得本地模型权重文件。
|
|
当您使用私有数据集完成微调训练后,可获得本地模型权重文件。
|
|
|
|
|
|
|
|
若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径替换至产线配置文件中的对应位置即可:
|
|
若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径替换至产线配置文件中的对应位置即可:
|
|
|
|
|
|
|
|
-```python
|
|
|
|
|
-......
|
|
|
|
|
- Pipeline:
|
|
|
|
|
- layout_model: PicoDet_layout_1x #可修改为微调后模型的本地路径
|
|
|
|
|
- table_model: SLANet #可修改为微调后模型的本地路径
|
|
|
|
|
- text_det_model: PP-OCRv4_mobile_det #可修改为微调后模型的本地路径
|
|
|
|
|
- text_rec_model: PP-OCRv4_mobile_rec #可修改为微调后模型的本地路径
|
|
|
|
|
- layout_batch_size: 1
|
|
|
|
|
- text_rec_batch_size: 1
|
|
|
|
|
- table_batch_size: 1
|
|
|
|
|
- device: "gpu:0"
|
|
|
|
|
-......
|
|
|
|
|
|
|
+```yaml
|
|
|
|
|
+SubModules:
|
|
|
|
|
+ LayoutDetection:
|
|
|
|
|
+ module_name: layout_detection
|
|
|
|
|
+ model_name: PicoDet_layout_1x_table
|
|
|
|
|
+ model_dir: null # 替换为微调后的版面区域检测模型权重路径
|
|
|
|
|
+
|
|
|
|
|
+ TableStructureRecognition:
|
|
|
|
|
+ module_name: table_structure_recognition
|
|
|
|
|
+ model_name: SLANet_plus
|
|
|
|
|
+ model_dir: null # 替换为微调后的表格结构识别模型权重路径
|
|
|
|
|
+
|
|
|
|
|
+SubPipelines:
|
|
|
|
|
+ DocPreprocessor:
|
|
|
|
|
+ pipeline_name: doc_preprocessor
|
|
|
|
|
+ use_doc_orientation_classify: True
|
|
|
|
|
+ use_doc_unwarping: True
|
|
|
|
|
+ SubModules:
|
|
|
|
|
+ DocOrientationClassify:
|
|
|
|
|
+ module_name: doc_text_orientation
|
|
|
|
|
+ model_name: PP-LCNet_x1_0_doc_ori
|
|
|
|
|
+ model_dir: null # 替换为微调后的文档图像方向分类模型权重路径
|
|
|
|
|
+
|
|
|
|
|
+ DocUnwarping:
|
|
|
|
|
+ module_name: image_unwarping
|
|
|
|
|
+ model_name: UVDoc
|
|
|
|
|
+ model_dir: null
|
|
|
|
|
+
|
|
|
|
|
+ GeneralOCR:
|
|
|
|
|
+ pipeline_name: OCR
|
|
|
|
|
+ text_type: general
|
|
|
|
|
+ use_doc_preprocessor: False
|
|
|
|
|
+ use_textline_orientation: False
|
|
|
|
|
+ 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
|
|
|
```
|
|
```
|
|
|
-随后, 参考本地体验中的命令行方式或 Python 脚本方式,加载修改后的产线配置文件即可。
|
|
|
|
|
|
|
+随后, 参考[2.2 本地体验](#22-本地体验)中的命令行方式或Python脚本方式,加载修改后的产线配置文件即可。
|
|
|
|
|
|
|
|
## 5. 多硬件支持
|
|
## 5. 多硬件支持
|
|
|
PaddleX 支持英伟达 GPU、昆仑芯 XPU、昇腾 NPU和寒武纪 MLU 等多种主流硬件设备,<b>仅需修改 `--device` 参数</b>即可完成不同硬件之间的无缝切换。
|
|
PaddleX 支持英伟达 GPU、昆仑芯 XPU、昇腾 NPU和寒武纪 MLU 等多种主流硬件设备,<b>仅需修改 `--device` 参数</b>即可完成不同硬件之间的无缝切换。
|
|
|
|
|
|
|
|
-例如,您使用英伟达 GPU 进行表格识别产线的推理,使用的 Python 命令为:
|
|
|
|
|
-
|
|
|
|
|
-```bash
|
|
|
|
|
-paddlex --pipeline table_recognition --input table_recognition.jpg --device gpu:0
|
|
|
|
|
-```
|
|
|
|
|
-此时,若您想将硬件切换为昇腾 NPU,仅需对 Python 命令中的 `--device` 修改为npu 即可:
|
|
|
|
|
|
|
+例如,您使用昇腾 NPU 进行 OCR 产线的推理,使用的 Python 命令为:
|
|
|
|
|
|
|
|
```bash
|
|
```bash
|
|
|
-paddlex --pipeline table_recognition --input table_recognition.jpg --device npu:0
|
|
|
|
|
|
|
+paddlex --pipeline table_recognition \
|
|
|
|
|
+ --input table_recognition.jpg \
|
|
|
|
|
+ --save_path ./output \
|
|
|
|
|
+ --device npu:0
|
|
|
```
|
|
```
|
|
|
若您想在更多种类的硬件上使用通用表格识别产线,请参考[PaddleX多硬件使用指南](../../../other_devices_support/multi_devices_use_guide.md)。
|
|
若您想在更多种类的硬件上使用通用表格识别产线,请参考[PaddleX多硬件使用指南](../../../other_devices_support/multi_devices_use_guide.md)。
|