From cf6f7012ad20e3cc16e5dac1ad264177d57d56cb Mon Sep 17 00:00:00 2001
From: WenmuZhou <572459439@qq.com>
Date: Tue, 16 Aug 2022 12:42:47 +0000
Subject: [PATCH] add structure predict doc
---
ppstructure/table/README.md | 20 ++++++++++++++++++++
ppstructure/table/README_ch.md | 21 ++++++++++++++++++++-
ppstructure/table/predict_structure.py | 5 ++++-
3 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/ppstructure/table/README.md b/ppstructure/table/README.md
index 5ac99ac8..7ecbe0ad 100644
--- a/ppstructure/table/README.md
+++ b/ppstructure/table/README.md
@@ -39,6 +39,8 @@ We evaluated the algorithm on the PubTabNet[1] eval dataset, and the
### 3.1 quick start
+- table recognition
+
```python
cd PaddleOCR/ppstructure
@@ -65,6 +67,24 @@ python3.7 table/predict_table.py \
After the operation is completed, the excel table of each image will be saved to the directory specified by the output field, and an html file will be produced in the directory to visually view the cell coordinates and the recognized table.
+- table structure recognition
+```python
+cd PaddleOCR/ppstructure
+
+# download model
+mkdir inference && cd inference
+# Download the PP-Structurev2 form recognition model and unzip it
+wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar
+cd ..
+# run
+python3.7 table/predict_structure.py \
+ --table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_infer \
+ --table_char_dict_path=../ppocr/utils/dict/table_structure_dict_ch.txt \
+ --image_dir=docs/table/table.jpg \
+ --output=../output/table
+```
+After the run is complete, the visualization of the detection frame of the cell will be saved to the directory specified by the output field.
+
### 3.2 Train
In this chapter, we only introduce the training of the table structure model, For model training of [text detection](../../doc/doc_en/detection_en.md) and [text recognition](../../doc/doc_en/recognition_en.md), please refer to the corresponding documents
diff --git a/ppstructure/table/README_ch.md b/ppstructure/table/README_ch.md
index a16de938..ac5029e7 100644
--- a/ppstructure/table/README_ch.md
+++ b/ppstructure/table/README_ch.md
@@ -49,6 +49,7 @@
### 3.1 快速开始
+- 表格识别
```python
cd PaddleOCR/ppstructure
@@ -61,7 +62,7 @@ wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_slim_infer
# 下载PP-Structurev2表格识别模型并解压
wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar
cd ..
-# 执行预测
+# 执行表格识别
python3.7 table/predict_table.py \
--det_model_dir=inference/ch_PP-OCRv3_det_slim_infer \
--rec_model_dir=inference/ch_PP-OCRv3_rec_slim_infer \
@@ -73,6 +74,24 @@ python3.7 table/predict_table.py \
```
运行完成后,每张图片的excel表格会保存到output字段指定的目录下,同时在该目录下回生产一个html文件,用于可视化查看单元格坐标和识别的表格。
+- 表格结构识别
+```python
+cd PaddleOCR/ppstructure
+
+# 下载模型
+mkdir inference && cd inference
+# 下载PP-Structurev2表格识别模型并解压
+wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar
+cd ..
+# 执行表格结构识别
+python3.7 table/predict_structure.py \
+ --table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_infer \
+ --table_char_dict_path=../ppocr/utils/dict/table_structure_dict_ch.txt \
+ --image_dir=docs/table/table.jpg \
+ --output=../output/table
+```
+运行完成后,单元格的检测框可视化会保存到output字段指定的目录下。
+
### 3.2 训练
diff --git a/ppstructure/table/predict_structure.py b/ppstructure/table/predict_structure.py
index c4a816fd..7198fb2b 100755
--- a/ppstructure/table/predict_structure.py
+++ b/ppstructure/table/predict_structure.py
@@ -147,7 +147,10 @@ def main(args):
f_w.write("result: {}, {}\n".format(structure_str_list,
bbox_list_str))
- img = draw_rectangle(image_file, bbox_list)
+ if len(bbox_list) > 0 and len(bbox_list[0]) == 4:
+ img = draw_rectangle(image_file, pred_res['cell_bbox'])
+ else:
+ img = utility.draw_boxes(img, bbox_list)
img_save_path = os.path.join(args.output,
os.path.basename(image_file))
cv2.imwrite(img_save_path, img)
--
GitLab