2022-04-18 15:28:22 +08:00
|
|
|
|
# 基于Python预测引擎推理
|
|
|
|
|
|
2022-04-22 13:24:45 +08:00
|
|
|
|
- [1. Structure](#1)
|
|
|
|
|
- [1.1 版面分析+表格识别](#1.1)
|
|
|
|
|
- [1.2 版面分析](#1.2)
|
|
|
|
|
- [1.3 表格识别](#1.3)
|
2022-08-22 09:52:23 +08:00
|
|
|
|
- [2. 关键信息抽取](#2)
|
2022-04-18 15:28:22 +08:00
|
|
|
|
|
|
|
|
|
<a name="1"></a>
|
2022-04-22 13:24:45 +08:00
|
|
|
|
## 1. Structure
|
|
|
|
|
进入`ppstructure`目录
|
2022-04-18 15:28:22 +08:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cd ppstructure
|
2022-04-22 13:24:45 +08:00
|
|
|
|
````
|
|
|
|
|
下载模型
|
|
|
|
|
```bash
|
2022-04-18 15:28:22 +08:00
|
|
|
|
mkdir inference && cd inference
|
|
|
|
|
# 下载PP-OCRv2文本检测模型并解压
|
|
|
|
|
wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_slim_quant_infer.tar && tar xf ch_PP-OCRv2_det_slim_quant_infer.tar
|
|
|
|
|
# 下载PP-OCRv2文本识别模型并解压
|
|
|
|
|
wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_slim_quant_infer.tar && tar xf ch_PP-OCRv2_rec_slim_quant_infer.tar
|
|
|
|
|
# 下载超轻量级英文表格预测模型并解压
|
|
|
|
|
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/table/en_ppocr_mobile_v2.0_table_structure_infer.tar && tar xf en_ppocr_mobile_v2.0_table_structure_infer.tar
|
|
|
|
|
cd ..
|
2022-04-22 13:24:45 +08:00
|
|
|
|
```
|
|
|
|
|
<a name="1.1"></a>
|
|
|
|
|
### 1.1 版面分析+表格识别
|
|
|
|
|
```bash
|
2022-04-18 15:28:22 +08:00
|
|
|
|
python3 predict_system.py --det_model_dir=inference/ch_PP-OCRv2_det_slim_quant_infer \
|
|
|
|
|
--rec_model_dir=inference/ch_PP-OCRv2_rec_slim_quant_infer \
|
|
|
|
|
--table_model_dir=inference/en_ppocr_mobile_v2.0_table_structure_infer \
|
2022-04-22 13:24:45 +08:00
|
|
|
|
--image_dir=./docs/table/1.png \
|
2022-04-18 15:28:22 +08:00
|
|
|
|
--rec_char_dict_path=../ppocr/utils/ppocr_keys_v1.txt \
|
|
|
|
|
--table_char_dict_path=../ppocr/utils/dict/table_structure_dict.txt \
|
2022-04-22 13:24:45 +08:00
|
|
|
|
--output=../output \
|
2022-04-18 15:28:22 +08:00
|
|
|
|
--vis_font_path=../doc/fonts/simfang.ttf
|
|
|
|
|
```
|
2022-04-22 13:24:45 +08:00
|
|
|
|
运行完成后,每张图片会在`output`字段指定的目录下的`structure`目录下有一个同名目录,图片里的每个表格会存储为一个excel,图片区域会被裁剪之后保存下来,excel文件和图片名为表格在图片里的坐标。详细的结果会存储在`res.txt`文件中。
|
|
|
|
|
|
|
|
|
|
<a name="1.2"></a>
|
|
|
|
|
### 1.2 版面分析
|
|
|
|
|
```bash
|
|
|
|
|
python3 predict_system.py --image_dir=./docs/table/1.png --table=false --ocr=false --output=../output/
|
|
|
|
|
```
|
|
|
|
|
运行完成后,每张图片会在`output`字段指定的目录下的`structure`目录下有一个同名目录,图片区域会被裁剪之后保存下来,图片名为表格在图片里的坐标。版面分析结果会存储在`res.txt`文件中。
|
|
|
|
|
|
|
|
|
|
<a name="1.3"></a>
|
|
|
|
|
### 1.3 表格识别
|
|
|
|
|
```bash
|
|
|
|
|
python3 predict_system.py --det_model_dir=inference/ch_PP-OCRv2_det_slim_quant_infer \
|
|
|
|
|
--rec_model_dir=inference/ch_PP-OCRv2_rec_slim_quant_infer \
|
|
|
|
|
--table_model_dir=inference/en_ppocr_mobile_v2.0_table_structure_infer \
|
|
|
|
|
--image_dir=./docs/table/table.jpg \
|
|
|
|
|
--rec_char_dict_path=../ppocr/utils/ppocr_keys_v1.txt \
|
|
|
|
|
--table_char_dict_path=../ppocr/utils/dict/table_structure_dict.txt \
|
|
|
|
|
--output=../output \
|
|
|
|
|
--vis_font_path=../doc/fonts/simfang.ttf \
|
|
|
|
|
--layout=false
|
|
|
|
|
```
|
|
|
|
|
运行完成后,每张图片会在`output`字段指定的目录下的`structure`目录下有一个同名目录,表格会存储为一个excel,excel文件名为`[0,0,img_h,img_w]`。
|
2022-04-18 15:28:22 +08:00
|
|
|
|
|
|
|
|
|
<a name="2"></a>
|
2022-08-22 09:52:23 +08:00
|
|
|
|
## 2. 关键信息抽取
|
2022-04-18 15:28:22 +08:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cd ppstructure
|
|
|
|
|
|
|
|
|
|
mkdir inference && cd inference
|
2022-08-22 09:52:23 +08:00
|
|
|
|
# 下载SER XFUND 模型并解压
|
|
|
|
|
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_infer.tar && tar -xf ser_vi_layoutxlm_xfund_infer.tar
|
2022-04-18 15:28:22 +08:00
|
|
|
|
cd ..
|
2022-08-22 09:52:23 +08:00
|
|
|
|
python3 kie/predict_kie_token_ser.py \
|
|
|
|
|
--kie_algorithm=LayoutXLM \
|
|
|
|
|
--ser_model_dir=../inference/ser_vi_layoutxlm_xfund_infer \
|
|
|
|
|
--image_dir=./docs/kie/input/zh_val_42.jpg \
|
|
|
|
|
--ser_dict_path=../ppocr/utils/dict/kie_dict/xfund_class_list.txt \
|
|
|
|
|
--vis_font_path=../doc/fonts/simfang.ttf \
|
|
|
|
|
--ocr_order_method="tb-yx"
|
2022-04-18 15:28:22 +08:00
|
|
|
|
```
|
2022-08-22 09:52:23 +08:00
|
|
|
|
|
2022-08-21 10:55:49 +08:00
|
|
|
|
运行完成后,每张图片会在`output`字段指定的目录下的`kie`目录下存放可视化之后的图片,图片名和输入图片名一致。
|