模型简介
模型特点
模型能力
使用案例
🚀 SLANet
SLANet是用于表格结构识别的模型,能够将不可编辑的表格图像转换为可编辑的表格格式(如HTML)。其输出的表格区域HTML代码,可作为输入传递给表格识别流程进行后续处理。
🚀 快速开始
安装
1. 安装PaddlePaddle
请参考以下命令,使用pip安装PaddlePaddle:
# 适用于CUDA11.8
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
# 适用于CUDA12.6
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
# 适用于CPU
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
PaddlePaddle安装的详细信息,请参考PaddlePaddle官方网站。
2. 安装PaddleOCR
从PyPI安装最新版本的PaddleOCR推理包:
python -m pip install paddleocr
模型使用
基础用法
你可以通过以下命令快速体验模型功能:
paddleocr table_structure_recognition \
--model_name SLANet \
-i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/6rfhb-CXOHowonjpBsaUJ.png
你也可以将表格分类模块的模型推理集成到你的项目中。在运行以下代码之前,请将示例图像下载到本地:
from paddleocr import TableStructureRecognition
model = TableStructureRecognition(model_name="SLANet")
output = model.predict(input="6rfhb-CXOHowonjpBsaUJ.png", batch_size=1)
for res in output:
res.print(json_format=False)
res.save_to_json("./output/res.json")
运行后,得到的结果如下:
{'res': {'input_path': '6rfhb-CXOHowonjpBsaUJ.png', 'page_index': None, 'bbox': [[2, 2, 60, 3, 60, 37, 2, 37], [50, 1, 193, 2, 195, 36, 51, 36], [175, 1, 252, 1, 255, 36, 178, 36], [246, 2, 321, 2, 322, 36, 248, 36], [316, 2, 390, 2, 391, 36, 318, 36], [392, 2, 493, 2, 493, 40, 393, 40], [5, 39, 52, 40, 52, 82, 5, 82], [65, 40, 181, 41, 181, 89, 65, 89], [186, 40, 252, 41, 252, 84, 186, 84], [251, 40, 323, 41, 324, 82, 252, 82], [323, 40, 385, 41, 386, 82, 324, 81], [384, 39, 496, 40, 496, 84, 385, 84], [5, 79, 52, 79, 52, 120, 5, 120], [63, 79, 182, 79, 183, 119, 63, 119], [188, 79, 252, 80, 252, 118, 189, 118], [253, 78, 324, 79, 326, 117, 254, 117], [322, 78, 383, 78, 385, 117, 324, 117], [397, 77, 495, 77, 495, 120, 398, 120], [4, 117, 50, 117, 51, 153, 4, 153], [67, 116, 181, 116, 183, 152, 68, 153], [190, 115, 251, 115, 252, 150, 191, 151], [253, 114, 324, 114, 326, 151, 255, 151], [324, 114, 383, 114, 384, 150, 326, 150], [398, 113, 494, 113, 494, 154, 400, 155], [1, 150, 53, 149, 53, 187, 1, 187], [73, 150, 179, 149, 180, 187, 73, 187], [188, 150, 254, 149, 255, 186, 189, 187], [253, 149, 326, 149, 328, 187, 255, 187], [325, 150, 383, 149, 385, 187, 327, 187], [393, 148, 493, 148, 493, 187, 394, 187]], 'structure': ['<html>', '<body>', '<table>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '</table>', '</body>', '</html>'], 'structure_score': 0.9999815}}
使用命令和参数说明的详细信息,请参考文档。
管道使用
单个模型的能力是有限的,但由多个模型组成的管道可以提供更强的能力来解决现实场景中的难题。
通用表格识别V2管道
通用表格识别V2管道用于解决表格识别任务,通过从图像中提取信息并以HTML或Excel格式输出。该管道包含8个模块:
- 表格分类模块
- 表格结构识别模块
- 表格单元格检测模块
- 文本检测模块
- 文本识别模块
- 布局区域检测模块(可选)
- 文档图像方向分类模块(可选)
- 文本图像去畸变模块(可选)
运行以下命令快速体验通用表格识别V2管道:
paddleocr table_recognition_v2 -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png \
--use_doc_orientation_classify False \
--use_doc_unwarping False \
--save_path ./output \
--device gpu:0
结果将打印到终端:
{'res': {'input_path': 'mabagznApI1k9R8qFoTLc.png', 'page_index': None, 'model_settings': {'use_doc_preprocessor': False, 'use_layout_detection': True, 'use_ocr_model': True}, 'layout_det_res': {'input_path': None, 'page_index': None, 'boxes': [{'cls_id': 8, 'label': 'table', 'score': 0.86655592918396, 'coordinate': [0.0125130415, 0.41920784, 1281.3737, 585.3884]}]}, 'overall_ocr_res': {'input_path': None, 'page_index': None, 'model_settings': {'use_doc_preprocessor': False, 'use_textline_orientation': False}, 'dt_polys': array([[[ 9, 21],
...,
[ 9, 59]],
...,
[[1046, 536],
...,
[1046, 573]]], 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': array([-1, ..., -1]), 'text_rec_score_thresh': 0, 'rec_texts': ['部门', '报销人', '报销事由', '批准人:', '单据', '张', '合计金额', '元', '车费票', '其', '火车费票', '飞机票', '中', '旅住宿费', '其他', '补贴'], 'rec_scores': array([0.99958128, ..., 0.99317062]), 'rec_polys': array([[[ 9, 21],
...,
[ 9, 59]],
...,
[[1046, 536],
...,
[1046, 573]]], dtype=int16), 'rec_boxes': array([[ 9, ..., 59],
...,
[1046, ..., 573]], dtype=int16)}, 'table_res_list': [{'cell_box_list': [array([ 0.13052222, ..., 73.08310249]), array([104.43082511, ..., 73.27777413]), array([319.39041221, ..., 73.30439308]), array([424.2436837 , ..., 73.44736794]), array([580.75836265, ..., 73.24003914]), array([723.04370201, ..., 73.22717598]), array([984.67315757, ..., 73.20420387]), array([1.25130415e-02, ..., 5.85419208e+02]), array([984.37072837, ..., 137.02281502]), array([984.26586998, ..., 201.22290352]), array([984.24017417, ..., 585.30775765]), array([1039.90606773, ..., 265.44664314]), array([1039.69549644, ..., 329.30540779]), array([1039.66546714, ..., 393.57319954]), array([1039.5122689 , ..., 457.74644783]), array([1039.55535972, ..., 521.73030403]), array([1039.58612144, ..., 585.09468392])], 'pred_html': '<html><body><table><tbody><tr><td>部门</td><td></td><td>报销人</td><td></td><td>报销事由</td><td></td><td colspan="2">批准人:</td></tr><tr><td colspan="6" rowspan="8"></td><td colspan="2">单据 张</td></tr><tr><td colspan="2">合计金额 元</td></tr><tr><td rowspan="6">其 中</td><td>车费票</td></tr><tr><td>火车费票</td></tr><tr><td>飞机票</td></tr><tr><td>旅住宿费</td></tr><tr><td>其他</td></tr><tr><td>补贴</td></tr></tbody></table></body></html>', 'table_ocr_pred': {'rec_polys': array([[[ 9, 21],
...,
[ 9, 59]],
...,
[[1046, 536],
...,
[1046, 573]]], dtype=int16), 'rec_texts': ['部门', '报销人', '报销事由', '批准人:', '单据', '张', '合计金额', '元', '车费票', '其', '火车费票', '飞机票', '中', '旅住宿费', '其他', '补贴'], 'rec_scores': array([0.99958128, ..., 0.99317062]), 'rec_boxes': array([[ 9, ..., 59],
...,
[1046, ..., 573]], dtype=int16)}}]}}
如果指定了save_path
,可视化结果将保存到save_path
目录下。可视化输出如下:
命令行方式适用于快速体验。对于项目集成,也只需要几行代码:
from paddleocr import TableRecognitionPipelineV2
pipeline = TableRecognitionPipelineV2(
use_doc_orientation_classify=False, # 使用use_doc_orientation_classify启用/禁用文档方向分类模型
use_doc_unwarping=False, # 使用use_doc_unwarping启用/禁用文档去畸变模块
)
# pipeline = TableRecognitionPipelineV2(use_doc_orientation_classify=True) # 使用use_doc_orientation_classify指定是否使用文档方向分类模型
# pipeline = TableRecognitionPipelineV2(use_doc_unwarping=True) # 使用use_doc_unwarping指定是否使用文本图像去畸变模块
# pipeline = TableRecognitionPipelineV2(device="gpu") # 使用device指定使用GPU进行模型推理
output = pipeline.predict("https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png")
for res in output:
res.print() ## 打印预测的结构化输出
res.save_to_img("./output/")
res.save_to_xlsx("./output/")
res.save_to_html("./output/")
res.save_to_json("./output/")
如果你想使用SLANet模型进行表格识别,只需更改模型名称并使用端到端预测模式,如下所示:
paddleocr table_recognition_v2 -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png \
--use_doc_orientation_classify False \
--use_doc_unwarping False \
--wired_table_structure_recognition_model_name SLANet \
--use_e2e_wired_table_rec_model True \
--wireless_table_structure_recognition_model_name SLANet \
--use_e2e_wireless_table_rec_model True \
--save_path ./output \
--device gpu:0
from paddleocr import TableRecognitionPipelineV2
pipeline = TableRecognitionPipelineV2(
use_doc_orientation_classify=False,
use_doc_unwarping=False,
wired_table_structure_recognition_model_name=SLANet, ## 用于有线表格识别
wireless_table_structure_recognition_model_name=SLANet, ## 用于无线表格识别
)
output = pipeline.predict(
"https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png",
use_e2e_wired_table_rec_model=True, ## 用于有线表格识别
use_e2e_wireless_table_rec_model=True, ## 用于无线表格识别
)
for res in output:
res.print() ## 打印预测的结构化输出
res.save_to_img("./output/")
res.save_to_xlsx("./output/")
res.save_to_html("./output/")
res.save_to_json("./output/")
使用命令和参数说明的详细信息,请参考文档。
PP-StructureV3
布局分析是一种从文档图像中提取结构化信息的技术。PP-StructureV3包括以下六个模块:
- 布局检测模块
- 通用OCR管道
- 文档图像预处理管道(可选)
- 表格识别管道(可选)
- 印章识别管道(可选)
- 公式识别管道(可选)
运行以下命令快速体验PP-StructureV3管道:
paddleocr pp_structurev3 -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mG4tnwfrvECoFMu-S9mxo.png \
--use_doc_orientation_classify False \
--use_doc_unwarping False \
--wired_table_structure_recognition_model_name SLANet \
--use_e2e_wired_table_rec_model True \
--wireless_table_structure_recognition_model_name SLANet \
--use_e2e_wireless_table_rec_model True \
--use_textline_orientation False \
--device gpu:0
结果将打印到终端。如果指定了save_path
,结果将保存到save_path
目录下。
只需几行代码即可体验管道的推理。以PP-StructureV3管道为例:
from paddleocr import PPStructureV3
pipeline = PPStructureV3(
wired_table_structure_recognition_model_name=SLANet, ## 用于有线表格识别
wireless_table_structure_recognition_model_name=SLANet, ## 用于无线表格识别
use_doc_orientation_classify=False, # 使用use_doc_orientation_classify启用/禁用文档方向分类模型
use_doc_unwarping=False, # 使用use_doc_unwarping启用/禁用文档去畸变模块
use_textline_orientation=False, # 使用use_textline_orientation启用/禁用文本行方向分类模型
device="gpu:0", # 使用device指定使用GPU进行模型推理
)
output = pipeline.predict(
"mG4tnwfrvECoFMu-S9mxo.png",
use_e2e_wired_table_rec_model=True, ## 用于有线表格识别
use_e2e_wireless_table_rec_model=True, ## 用于无线表格识别
)
for res in output:
res.print() # 打印结构化预测输出
res.save_to_json(save_path="output") ## 以JSON格式保存当前图像的结构化结果
res.save_to_markdown(save_path="output") ## 以Markdown格式保存当前图像的结果
管道中使用的默认模型是SLANeXt_wired
和SLANeXt_wireless
,因此需要通过参数指定为SLANet
。使用命令和参数说明的详细信息,请参考文档。
✨ 主要特性
- 表格结构识别:能够识别表格中行列和单元格的位置,将表格图像转换为可编辑的HTML格式。
- 多模块集成:可与多个模型集成,组成管道解决复杂的表格识别任务。
- 多模式支持:支持正常模式和高性能模式,满足不同场景需求。
📚 详细文档
📄 许可证
本项目采用Apache-2.0许可证。
📊 模型信息
属性 | 详情 |
---|---|
模型类型 | SLANet |
准确率(%) | 59.52 |
GPU推理时间(ms) [正常模式 / 高性能模式] |
103.08 / 103.08 |
CPU推理时间(ms) [正常模式 / 高性能模式] |
197.99 / 197.99 |
模型存储大小(M) | 6.9 |










