RapidTable 是基于深度学习的表格结构识别模型,可自动识别图像中表格的单元格位置和结构。本仓库提供 SLANet+ 模型在昇腾 Ascend NPU 上的推理适配。
| 文件 | 说明 | 大小 |
|---|---|---|
cycle_center_net.onnx | 表格结构识别主模型 | 72 MB |
slanet-plus.onnx | SLANet+ 表格识别模型 | 7.8 MB |
ch_ppstructure_mobile_v2_SLANet.onnx | 中文 SLANet 模型 | 7.8 MB |
en_ppstructure_mobile_v2_SLANet.onnx | 英文 SLANet 模型 | 7.7 MB |
unet.onnx | UNet 表格检测 | 8.3 MB |
lore/detect.onnx | LoRE 表格检测 | 44 MB |
lore/process.onnx | LoRE 后处理 | 44 MB |
unitable/encoder.pth | UniTable 编码器 (PyTorch) | 346 MB |
unitable/decoder.pth | UniTable 解码器 (PyTorch) | 160 MB |
| 依赖 | 版本 |
|---|---|
| Python | >= 3.9 |
| rapid-table | >= 3.0.0 |
| onnxruntime-cann | >= 1.24.0 |
| numpy | < 2.0 |
| opencv-python-headless | >= 4.5 |
| Pillow | >= 9.0 |
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple rapid-table onnxruntime-cann "numpy<2.0" opencv-python-headless Pillow本模型通过 onnxruntime-cann 的 CANNExecutionProvider 在昇腾 NPU 上进行推理加速。推理时通过环境变量 ORT_DEFAULT_PROVIDER 控制使用 CPU 还是 NPU 后端:
ORT_DEFAULT_PROVIDER=CPUExecutionProviderORT_DEFAULT_PROVIDER=CANNExecutionProviderpython3 inference.py --image test_table.jpg --device cpupython3 inference.py --image test_table.jpg --device npupython3 compare_cpu_npu.py使用测试图片 test_table.jpg(包含一个 5x4 的简单表格),RapidTable 检测到 24 个单元格:
| 单元格 | X 范围 | Y 范围 |
|---|---|---|
| Cell[0] | [1.4, 152.2] | [1.9, 43.3] |
| Cell[1] | [151.2, 302.9] | [1.7, 44.3] |
| Cell[2] | [298.1, 451.9] | [1.8, 47.8] |
| Cell[3] | [449.2, 598.7] | [1.9, 48.8] |
| Cell[4] | [1.6, 146.6] | [49.5, 100.0] |
| Cell[5] | [153.3, 302.9] | [50.3, 99.7] |
| Cell[6] | [298.4, 453.2] | [49.6, 99.9] |
| Cell[7] | [447.9, 598.6] | [49.1, 100.6] |
| 指标 | CPU | NPU | 差异 |
|---|---|---|---|
| 检测单元格数 | 24 | 24 | 0 |
| 完全匹配单元格 | - | - | 24/24 (100.00%) |
| 最大边界框差异 | - | - | 0.000000 |
NPU 与 CPU 推理结果误差为 0.00%,符合精度误差小于 1% 的要求。
| 后端 | 推理耗时 (s) |
|---|---|
| CPU | 0.3455 |
| NPU (Ascend 910) | 0.2225 |
NPU 推理速度约为 CPU 的 1.55 倍。
import os
from rapid_table import RapidTable, RapidTableInput, ModelType
# CPU 推理
os.environ['ORT_DEFAULT_PROVIDER'] = 'CPUExecutionProvider'
cfg = RapidTableInput(model_type=ModelType.SLANETPLUS, use_ocr=False)
engine = RapidTable(cfg)
result = engine('test_table.jpg')
# NPU 推理
os.environ['ORT_DEFAULT_PROVIDER'] = 'CANNExecutionProvider'
cfg = RapidTableInput(model_type=ModelType.SLANETPLUS, use_ocr=False)
engine = RapidTable(cfg)
result = engine('test_table.jpg')result.cell_bboxes 包含每个单元格的 8 个坐标值(4 个角点的 x, y 坐标)。
result.pred_htmls 包含表格的 HTML 结构表示(当 use_ocr=True 时)。

本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理:
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpu推理完成后会输出推理结果和耗时,表明模型在 NPU 上推理成功。
#+NPU #+表格识别 #+CV #+表格结构 #+SLANet #+昇腾
本仓库仅用于昇腾 NPU 适配,原始模型版权归 RapidAI 所有。