https://github.com/swhl/lgpma_infer
表格结构识别LGPMA推理
https://github.com/swhl/lgpma_infer
Last synced: 11 months ago
JSON representation
表格结构识别LGPMA推理
- Host: GitHub
- URL: https://github.com/swhl/lgpma_infer
- Owner: SWHL
- License: apache-2.0
- Created: 2022-05-31T11:22:08.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-17T09:25:51.000Z (over 3 years ago)
- Last Synced: 2025-06-27T21:41:16.617Z (about 1 year ago)
- Language: Python
- Size: 1.62 MB
- Stars: 23
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## LGPMA_Infer
- 整理自于: [DAVAR-Lab-OCR](https://github.com/hikopensource/DAVAR-Lab-OCR/tree/main/demo/table_recognition/lgpma)
- 因为该模型都是基于英文表格训练而来,因此对于中文表格识别能力较差,但是也具有一定的适应能力。
- 相关介绍博客:[论文阅读: (ICDAR2021 海康威视)LGPMA(表格识别算法)及官方源码对应解读](http://t.csdn.cn/aToa2)
#### 模型下载
- [pth (Access Code: zUoX)](https://one.hikvision.com/#/link/u9YgYyoPW3hLw6iolFoA) 177M ResNet50
- 下载之后放到`models`目录下即可
#### 环境搭建
- `mmdet`: 该库不用安装,因为仓库中已经有了mmdet离线包,该包是下载的2.25.0,为了可以转onnx,里面做了一些修改,不影响现在的推理
- 其他库安装:
```shell
pip install -r requirements.txt -i https://pypi.douban.com/simple/
```
#### demo运行
```shell
python test_pub.py
# 输出结果,会在output目录下保存绘制框线的图像
# OK
```
- 结果示例:
- 原图:

- 识别结果:

#### 模型转onnx
- 状态:可以成功转换,转换时也特别耗费内存-_-!,同时因基于ONNXRuntime推理时,太耗费内存,而放弃
- 转换脚本:
```shell
bash model_2_onnx.sh
```
- 转换之后onnx模型下载[link](https://drive.google.com/file/d/1t2muqUFif-jbbTqQUrWGHjHZo3MgYxgQ/view?usp=sharing),仅供参考,推理尚未成功
- 验证推理代码:
```python
# 在davarocr/davar_common/apis/inference.py#L119行插入
import onnxruntime
session = onnxruntime.InferenceSession('lgpma.onnx')
input_name = session.get_inputs()[0].name
inputs = {
input_name: data['img'][0].numpy().astype(np.float32)
}
outs = session.run(None, inputs)
```
#### 参考链接
- [mmdet/pytorch2onnx](https://github.com/open-mmlab/mmdetection/blob/master/docs/en/tutorials/pytorch2onnx.md)
- [ONNX and grid_sample layer](https://github.com/pytorch/pytorch/issues/27212)
- [Pytorch转ONNX遇到的问题及解决方案](https://blog.csdn.net/JoeyChen1219/article/details/121141318)