飞桨PaddlePaddle/SLANeXt_wired
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

SLANeXt_wired

简介

表格结构识别是表格识别系统的重要组成部分,能够将不可编辑的表格图像转换为可编辑的表格格式(如HTML)。表格结构识别的目标是识别表格中行、列和单元格的位置。该模块的性能直接影响整个表格识别系统的准确性和效率。表格结构识别模块通常输出表格区域的HTML代码,然后将其作为输入传递给表格识别流水线进行进一步处理。

模型准确率(%)GPU推理时间(毫秒)
[普通模式/高性能模式]
CPU推理时间(毫秒)
[普通模式/高性能模式]
模型存储大小(M)
SLANeXt_wired69.65----351M

注意:SLANeXt_wired的准确率来源于与SLANeXt_wireless的联合测试结果。

安装

  1. PaddlePaddle

请参考以下命令使用pip安装PaddlePaddle:

# for CUDA11.8
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/

# for CUDA12.6
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/

# for CPU
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/

关于 PaddlePaddle 的安装详情,请参考 PaddlePaddle 官方网站。

  1. PaddleOCR

从 PyPI 安装最新版本的 PaddleOCR 推理包:

python -m pip install paddleocr

模型使用方法

您可以通过一条命令快速体验功能:

paddleocr table_structure_recognition \
    --model_name SLANeXt_wired \
    -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/JUU_5wJWVo4PcmJhSdIo3.png

您还可以将表格分类模块的模型推理集成到您的项目中。在运行以下代码之前,请将示例图片下载到您的本地计算机。

from paddleocr import TableStructureRecognition
model = TableStructureRecognition(model_name="SLANeXt_wired")
output = model.predict(input="JUU_5wJWVo4PcmJhSdIo3.png", batch_size=1)
for res in output:
    res.print(json_format=False)
    res.save_to_json("./output/res.json")

运行后,得到的结果如下:

{'res': {'input_path': 'JUU_5wJWVo4PcmJhSdIo3.png', 'page_index': None, 'bbox': [[12, 4, 96, 5, 87, 43, 11, 40], [188, 4, 276, 5, 261, 50, 174, 48], [352, 4, 477, 4, 477, 57, 341, 55], [9, 36, 133, 38, 126, 95, 8, 93], [211, 40, 282, 40, 269, 104, 198, 103], [330, 38, 476, 39, 476, 106, 320, 106], [49, 72, 107, 76, 105, 187, 47, 182], [215, 78, 284, 80, 280, 180, 212, 177], [334, 72, 476, 73, 476, 175, 333, 175], [6, 140, 145, 153, 149, 247, 6, 233], [197, 149, 282, 158, 285, 254, 201, 245], [302, 144, 476, 152, 476, 254, 305, 246], [32, 196, 100, 208, 107, 312, 34, 299], [193, 198, 270, 209, 282, 318, 206, 309], [322, 192, 475, 202, 475, 327, 333, 319], [5, 257, 122, 271, 137, 379, 6, 370], [171, 262, 260, 273, 277, 392, 188, 386], [296, 257, 476, 265, 476, 398, 313, 394], [17, 319, 107, 322, 120, 454, 20, 454], [155, 319, 266, 320, 284, 457, 173, 457], [288, 307, 475, 308, 475, 460, 307, 460], [12, 426, 101, 425, 103, 475, 12, 475], [154, 399, 279, 390, 285, 475, 160, 476], [289, 388, 475, 380, 475, 475, 297, 476]], 'structure': ['<html>', '<body>', '<table>', '<thead>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '</thead>', '<tbody>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '</tbody>', '</table>', '</body>', '</html>'], 'structure_score': 0.9998931}}

关于使用命令和参数说明的详细信息,请参考文档。

流水线使用

单个模型的能力是有限的。但由多个模型组成的流水线能够提供更强的能力,以解决现实场景中的复杂问题。

通用表格识别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 目录下。可视化输出如下所示:

image/jpeg

命令行方式适用于快速体验。对于项目集成,同样仅需少量代码即可:

from paddleocr import TableRecognitionPipelineV2

pipeline = TableRecognitionPipelineV2(
    use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
    use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
)
# pipeline = TableRecognitionPipelineV2(use_doc_orientation_classify=True) # Specify whether to use the document orientation classification model with use_doc_orientation_classify
# pipeline = TableRecognitionPipelineV2(use_doc_unwarping=True) # Specify whether to use the text image unwarping module with use_doc_unwarping
# pipeline = TableRecognitionPipelineV2(device="gpu") # Specify the device to use GPU for model inference
output = pipeline.predict("https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png")
for res in output:
    res.print() ## Print the predicted structured output
    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 \
    --use_textline_orientation False \
    --device gpu:0

结果将打印到终端。如果指定了 save_path,结果将保存在 save_path 下。

只需几行代码即可体验该流水线的推理。以 PP-StructureV3 流水线为例:

from paddleocr import PPStructureV3

pipeline = PPStructureV3(
    use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
    use_doc_unwarping=False,    # Use use_doc_unwarping to enable/disable document unwarping module
    use_textline_orientation=False, # Use use_textline_orientation to enable/disable textline orientation classification model
    device="gpu:0", # Use device to specify GPU for model inference
    )
output = pipeline.predict(".mG4tnwfrvECoFMu-S9mxo.png")
for res in output:
    res.print() # Print the structured prediction output
    res.save_to_json(save_path="output") ## Save the current image's structured result in JSON format
    res.save_to_markdown(save_path="output") ## Save the current image's result in Markdown format

有关使用命令和参数说明的详细信息,请参阅文档。

链接

PaddleOCR 代码库

PaddleOCR 文档