This commit is contained in:
433
docs/version2.x/ppstructure/infer_deploy/cpp_infer.en.md
Normal file
433
docs/version2.x/ppstructure/infer_deploy/cpp_infer.en.md
Normal file
@@ -0,0 +1,433 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Server-side C++ Inference
|
||||
|
||||
This chapter introduces the C++ deployment steps of the PaddleOCR model. C++ is better than Python in terms of performance. Therefore, in CPU and GPU deployment scenarios, C++ deployment is mostly used.
|
||||
This section will introduce how to configure the C++ environment and deploy PaddleOCR in Linux (CPU\GPU) environment. For Windows deployment please refer to [Windows](../../ppocr/infer_deploy/windows_vs2019_build.en.md) compilation guidelines.
|
||||
|
||||
## 1. Prepare the Environment
|
||||
|
||||
### 1.1 Environment
|
||||
|
||||
- Linux, docker is recommended.
|
||||
- Windows.
|
||||
|
||||
### 1.2 Compile OpenCV
|
||||
|
||||
- First of all, you need to download the source code compiled package in the Linux environment from the OpenCV official website. Taking OpenCV 3.4.7 as an example, the download command is as follows.
|
||||
|
||||
```bash linenums="1"
|
||||
cd deploy/cpp_infer
|
||||
wget https://paddleocr.bj.bcebos.com/libs/opencv/opencv-3.4.7.tar.gz
|
||||
tar -xf opencv-3.4.7.tar.gz
|
||||
```
|
||||
|
||||
Finally, you will see the folder of `opencv-3.4.7/` in the current directory.
|
||||
|
||||
- Compile OpenCV, the OpenCV source path (`root_path`) and installation path (`install_path`) should be set by yourself. Enter the OpenCV source code path and compile it in the following way.
|
||||
|
||||
```bash linenums="1"
|
||||
root_path=your_opencv_root_path
|
||||
install_path=${root_path}/opencv3
|
||||
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX=${install_path} \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DWITH_IPP=OFF \
|
||||
-DBUILD_IPP_IW=OFF \
|
||||
-DWITH_LAPACK=OFF \
|
||||
-DWITH_EIGEN=OFF \
|
||||
-DCMAKE_INSTALL_LIBDIR=lib64 \
|
||||
-DWITH_ZLIB=ON \
|
||||
-DBUILD_ZLIB=ON \
|
||||
-DWITH_JPEG=ON \
|
||||
-DBUILD_JPEG=ON \
|
||||
-DWITH_PNG=ON \
|
||||
-DBUILD_PNG=ON \
|
||||
-DWITH_TIFF=ON \
|
||||
-DBUILD_TIFF=ON
|
||||
|
||||
make -j
|
||||
make install
|
||||
```
|
||||
|
||||
In the above commands, `root_path` is the downloaded OpenCV source code path, and `install_path` is the installation path of OpenCV. After `make install` is completed, the OpenCV header file and library file will be generated in this folder for later OCR source code compilation.
|
||||
|
||||
The final file structure under the OpenCV installation path is as follows.
|
||||
|
||||
```
|
||||
opencv3/
|
||||
|-- bin
|
||||
|-- include
|
||||
|-- lib
|
||||
|-- lib64
|
||||
|-- share
|
||||
```
|
||||
|
||||
### 1.3 Compile or Download or the Paddle Inference Library
|
||||
|
||||
- There are 2 ways to obtain the Paddle inference library, described in detail below.
|
||||
|
||||
#### 1.3.1 Direct download and installation
|
||||
|
||||
[Paddle inference library official website](https://www.paddlepaddle.org.cn/inference/master/guides/install/download_lib.html#linux). You can review and select the appropriate version of the inference library on the official website.
|
||||
|
||||
- After downloading, use the following command to extract files.
|
||||
|
||||
```bash linenums="1"
|
||||
tar -xf paddle_inference.tgz
|
||||
```
|
||||
|
||||
Finally you will see the folder of `paddle_inference/` in the current path.
|
||||
|
||||
#### 1.3.2 Compile the inference source code
|
||||
|
||||
- If you want to get the latest Paddle inference library features, you can download the latest code from Paddle GitHub repository and compile the inference library from the source code. It is recommended to download the inference library with paddle version greater than or equal to 2.0.1.
|
||||
|
||||
- You can refer to [Paddle inference library](https://www.paddlepaddle.org.cn/documentation/docs/en/advanced_guide/inference_deployment/inference/build_and_install_lib_en.html) to get the Paddle source code from GitHub, and then compile To generate the latest inference library. The method of using git to access the code is as follows.
|
||||
|
||||
```bash linenums="1"
|
||||
git clone https://github.com/PaddlePaddle/Paddle.git
|
||||
git checkout develop
|
||||
```
|
||||
|
||||
- Enter the Paddle directory and run the following commands to compile the paddle inference library.
|
||||
|
||||
```bash linenums="1"
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
cmake .. \
|
||||
-DWITH_CONTRIB=OFF \
|
||||
-DWITH_MKL=ON \
|
||||
-DWITH_MKLDNN=ON \
|
||||
-DWITH_TESTING=OFF \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DWITH_INFERENCE_API_TEST=OFF \
|
||||
-DON_INFER=ON \
|
||||
-DWITH_PYTHON=ON
|
||||
make -j
|
||||
make inference_lib_dist
|
||||
```
|
||||
|
||||
For more compilation parameter options, please refer to the [document](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.0/guides/05_inference_deployment/inference/build_and_install_lib_cn.html#congyuanmabianyi).
|
||||
|
||||
- After the compilation process, you can see the following files in the folder of `build/paddle_inference_install_dir/`.
|
||||
|
||||
```text linenums="1"
|
||||
build/paddle_inference_install_dir/
|
||||
|-- CMakeCache.txt
|
||||
|-- paddle
|
||||
|-- third_party
|
||||
|-- version.txt
|
||||
```
|
||||
|
||||
`paddle` is the Paddle library required for C++ prediction later, and `version.txt` contains the version information of the current inference library.
|
||||
|
||||
## 2. Compile and Run the Demo
|
||||
|
||||
### 2.1 Export the inference model
|
||||
|
||||
- You can refer to [Model inference](./python_infer.en.md) and export the inference model. After the model is exported, assuming it is placed in the `inference` directory, the directory structure is as follows.
|
||||
|
||||
```text linenums="1"
|
||||
inference/
|
||||
|-- det_db
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
|-- rec_rcnn
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
|-- cls
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
|-- table
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
|-- layout
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
```
|
||||
|
||||
### 2.2 Compile PaddleOCR C++ inference demo
|
||||
|
||||
- The compilation commands are as follows. The addresses of Paddle C++ inference library, opencv and other Dependencies need to be replaced with the actual addresses on your own machines.
|
||||
|
||||
```bash linenums="1"
|
||||
sh tools/build.sh
|
||||
```
|
||||
|
||||
Specifically, you should modify the paths in `tools/build.sh`. The related content is as follows.
|
||||
|
||||
```bash linenums="1"
|
||||
OPENCV_DIR=your_opencv_dir
|
||||
LIB_DIR=your_paddle_inference_dir
|
||||
CUDA_LIB_DIR=your_cuda_lib_dir
|
||||
CUDNN_LIB_DIR=your_cudnn_lib_dir
|
||||
```
|
||||
|
||||
`OPENCV_DIR` is the OpenCV installation path; `LIB_DIR` is the download (`paddle_inference` folder)
|
||||
or the generated Paddle inference library path (`build/paddle_inference_install_dir` folder);
|
||||
`CUDA_LIB_DIR` is the CUDA library file path, in docker; it is `/usr/local/cuda/lib64`; `CUDNN_LIB_DIR` is the cuDNN library file path, in docker it is `/usr/lib/x86_64-linux-gnu/`.
|
||||
|
||||
- After the compilation is completed, an executable file named `ppocr` will be generated in the `build` folder.
|
||||
|
||||
### 2.3 Run the demo
|
||||
|
||||
Execute the built executable file:
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr [--param1] [--param2] [...]
|
||||
```
|
||||
|
||||
**Note**:ppocr uses the `PP-OCRv3` model by default, and the input shape used by the recognition model is `3, 48, 320`, if you want to use the old version model, you should add the parameter `--rec_img_h=32`.
|
||||
|
||||
Specifically,
|
||||
|
||||
#### 1. det+cls+rec
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--rec_model_dir=inference/rec_rcnn \
|
||||
--cls_model_dir=inference/cls \
|
||||
--image_dir=../../doc/imgs/12.jpg \
|
||||
--use_angle_cls=true \
|
||||
--det=true \
|
||||
--rec=true \
|
||||
--cls=true \
|
||||
```
|
||||
|
||||
##### 2. det+rec
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--rec_model_dir=inference/rec_rcnn \
|
||||
--image_dir=../../doc/imgs/12.jpg \
|
||||
--use_angle_cls=false \
|
||||
--det=true \
|
||||
--rec=true \
|
||||
--cls=false \
|
||||
```
|
||||
|
||||
##### 3. det
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--image_dir=../../doc/imgs/12.jpg \
|
||||
--det=true \
|
||||
--rec=false
|
||||
```
|
||||
|
||||
##### 4. cls+rec
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --rec_model_dir=inference/rec_rcnn \
|
||||
--cls_model_dir=inference/cls \
|
||||
--image_dir=../../doc/imgs_words/ch/word_1.jpg \
|
||||
--use_angle_cls=true \
|
||||
--det=false \
|
||||
--rec=true \
|
||||
--cls=true \
|
||||
```
|
||||
|
||||
##### 5. rec
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --rec_model_dir=inference/rec_rcnn \
|
||||
--image_dir=../../doc/imgs_words/ch/word_1.jpg \
|
||||
--use_angle_cls=false \
|
||||
--det=false \
|
||||
--rec=true \
|
||||
--cls=false \
|
||||
```
|
||||
|
||||
##### 6. cls
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --cls_model_dir=inference/cls \
|
||||
--cls_model_dir=inference/cls \
|
||||
--image_dir=../../doc/imgs_words/ch/word_1.jpg \
|
||||
--use_angle_cls=true \
|
||||
--det=false \
|
||||
--rec=false \
|
||||
--cls=true \
|
||||
```
|
||||
|
||||
##### 7. layout+table
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--rec_model_dir=inference/rec_rcnn \
|
||||
--table_model_dir=inference/table \
|
||||
--image_dir=../../ppstructure/docs/table/table.jpg \
|
||||
--layout_model_dir=inference/layout \
|
||||
--type=structure \
|
||||
--table=true \
|
||||
--layout=true
|
||||
```
|
||||
|
||||
##### 8. layout
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --layout_model_dir=inference/layout \
|
||||
--image_dir=../../ppstructure/docs/table/1.png \
|
||||
--type=structure \
|
||||
--table=false \
|
||||
--layout=true \
|
||||
--det=false \
|
||||
--rec=false
|
||||
```
|
||||
|
||||
##### 9. table
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--rec_model_dir=inference/rec_rcnn \
|
||||
--table_model_dir=inference/table \
|
||||
--image_dir=../../ppstructure/docs/table/table.jpg \
|
||||
--type=structure \
|
||||
--table=true
|
||||
```
|
||||
|
||||
More parameters are as follows,
|
||||
|
||||
- Common parameters
|
||||
|
||||
|parameter|data type|default|meaning|
|
||||
| --- | --- | --- | --- |
|
||||
|use_gpu|bool|false|Whether to use GPU|
|
||||
|gpu_id|int|0|GPU id when use_gpu is true|
|
||||
|gpu_mem|int|4000|GPU memory requested|
|
||||
|cpu_math_library_num_threads|int|10|Number of threads when using CPU inference. When machine cores is enough, the large the value, the faster the inference speed|
|
||||
|enable_mkldnn|bool|true|Whether to use mkdlnn library|
|
||||
|output|str|./output|Path where visualization results are saved|
|
||||
|
||||
- forward
|
||||
|
||||
|parameter|data type|default|meaning|
|
||||
| :---: | :---: | :---: | :---: |
|
||||
|det|bool|true|Whether to perform text detection in the forward direction|
|
||||
|rec|bool|true|Whether to perform text recognition in the forward direction|
|
||||
|cls|bool|false|Whether to perform text direction classification in the forward direction|
|
||||
|
||||
- Detection related parameters
|
||||
|
||||
|parameter|data type|default|meaning|
|
||||
| --- | --- | --- | --- |
|
||||
|det_model_dir|string|-|Address of detection inference model|
|
||||
|max_side_len|int|960|Limit the maximum image height and width to 960|
|
||||
|det_db_thresh|float|0.3|Used to filter the binarized image of DB prediction, setting 0.-0.3 has no obvious effect on the result|
|
||||
|det_db_box_thresh|float|0.5|DB post-processing filter box threshold, if there is a missing box detected, it can be reduced as appropriate|
|
||||
|det_db_unclip_ratio|float|1.6|Indicates the compactness of the text box, the smaller the value, the closer the text box to the text|
|
||||
|det_db_score_mode|string|slow| slow: use polygon box to calculate bbox score, fast: use rectangle box to calculate. Use rectangular box to calculate faster, and polygonal box more accurate for curved text area.|
|
||||
|visualize|bool|true|Whether to visualize the results,when it is set as true, the prediction results will be saved in the folder specified by the `output` field on an image with the same name as the input image.|
|
||||
|
||||
- Classifier related parameters
|
||||
|
||||
|parameter|data type|default|meaning|
|
||||
| --- | --- | --- | --- |
|
||||
|use_angle_cls|bool|false|Whether to use the direction classifier|
|
||||
|cls_model_dir|string|-|Address of direction classifier inference model|
|
||||
|cls_thresh|float|0.9|Score threshold of the direction classifier|
|
||||
|cls_batch_num|int|1|batch size of classifier|
|
||||
|
||||
- Recognition related parameters
|
||||
|
||||
|parameter|data type|default|meaning|
|
||||
| --- | --- | --- | --- |
|
||||
|rec_model_dir|string|-|Address of recognition inference model|
|
||||
|rec_char_dict_path|string|../../ppocr/utils/ppocr_keys_v1.txt|dictionary file|
|
||||
|rec_batch_num|int|6|batch size of recognition|
|
||||
|rec_img_h|int|48|image height of recognition|
|
||||
|rec_img_w|int|320|image width of recognition|
|
||||
|
||||
- Layout related parameters
|
||||
|
||||
|parameter|data type|default|meaning|
|
||||
| :---: | :---: | :---: | :---: |
|
||||
|layout_model_dir|string|-| Address of layout inference model|
|
||||
|layout_dict_path|string|../../ppocr/utils/dict/layout_dict/layout_publaynet_dict.txt|dictionary file|
|
||||
|layout_score_threshold|float|0.5|Threshold of score.|
|
||||
|layout_nms_threshold|float|0.5|Threshold of nms.|
|
||||
|
||||
- Table recognition related parameters
|
||||
|
||||
|parameter|data type|default|meaning|
|
||||
| :---: | :---: | :---: | :---: |
|
||||
|table_model_dir|string|-|Address of table recognition inference model|
|
||||
|table_char_dict_path|string|../../ppocr/utils/dict/table_structure_dict.txt|dictionary file|
|
||||
|table_max_len|int|488|The size of the long side of the input image of the table recognition model, the final input image size of the network is(table_max_len,table_max_len)|
|
||||
|merge_no_span_structure|bool|true|Whether to merge <td> and </td> to <td></td|
|
||||
|
||||
- Multi-language inference is also supported in PaddleOCR, you can refer to [recognition tutorial](../../ppocr/blog/multi_languages.en.md) for more supported languages and models in PaddleOCR. Specifically, if you want to infer using multi-language models, you just need to modify values of `rec_char_dict_path` and `rec_model_dir`.
|
||||
|
||||
The detection results will be shown on the screen, which is as follows.
|
||||
|
||||
```bash linenums="1"
|
||||
predict img: ../../doc/imgs/12.jpg
|
||||
../../doc/imgs/12.jpg
|
||||
0 det boxes: [[74,553],[427,542],[428,571],[75,582]] rec text: 打浦路252935号 rec score: 0.947724
|
||||
1 det boxes: [[23,507],[513,488],[515,529],[24,548]] rec text: 绿洲仕格维花园公寓 rec score: 0.993728
|
||||
2 det boxes: [[187,456],[399,448],[400,480],[188,488]] rec text: 打浦路15号 rec score: 0.964994
|
||||
3 det boxes: [[42,413],[483,391],[484,428],[43,450]] rec text: 上海斯格威铂尔大酒店 rec score: 0.980086
|
||||
The detection visualized image saved in ./output//12.jpg
|
||||
```
|
||||
|
||||
- layout+table
|
||||
|
||||
```bash linenums="1"
|
||||
predict img: ../../ppstructure/docs/table/1.png
|
||||
0 type: text, region: [12,729,410,848], score: 0.781044, res: count of ocr result is : 7
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[4,1],[79,1],[79,12],[4,12]] rec text: CTW1500. rec score: 0.769472
|
||||
...
|
||||
6 det boxes: [[4,99],[391,99],[391,112],[4,112]] rec text: sate-of-the-artmethods[12.34.36l.ourapproachachieves rec score: 0.90414
|
||||
********** end print ocr result **********
|
||||
1 type: text, region: [69,342,342,359], score: 0.703666, res: count of ocr result is : 1
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[8,2],[269,2],[269,13],[8,13]] rec text: Table6.Experimentalresults on CTW-1500 rec score: 0.890454
|
||||
********** end print ocr result **********
|
||||
2 type: text, region: [70,316,706,332], score: 0.659738, res: count of ocr result is : 2
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[373,2],[630,2],[630,11],[373,11]] rec text: oroposals.andthegreencontoursarefinal rec score: 0.919729
|
||||
1 det boxes: [[8,3],[357,3],[357,11],[8,11]] rec text: Visualexperimentalresultshebluecontoursareboundar rec score: 0.915963
|
||||
********** end print ocr result **********
|
||||
3 type: text, region: [489,342,789,359], score: 0.630538, res: count of ocr result is : 1
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[8,2],[294,2],[294,14],[8,14]] rec text: Table7.Experimentalresults onMSRA-TD500 rec score: 0.942251
|
||||
********** end print ocr result **********
|
||||
4 type: text, region: [444,751,841,848], score: 0.607345, res: count of ocr result is : 5
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[19,3],[389,3],[389,17],[19,17]] rec text: Inthispaper,weproposeanovel adaptivebound rec score: 0.941031
|
||||
1 det boxes: [[4,22],[390,22],[390,36],[4,36]] rec text: aryproposalnetworkforarbitraryshapetextdetection rec score: 0.960172
|
||||
2 det boxes: [[4,42],[392,42],[392,56],[4,56]] rec text: whichadoptanboundaryproposalmodeltogeneratecoarse rec score: 0.934647
|
||||
3 det boxes: [[4,61],[389,61],[389,75],[4,75]] rec text: ooundaryproposals,andthenadoptanadaptiveboundary rec score: 0.946296
|
||||
4 det boxes: [[5,80],[387,80],[387,93],[5,93]] rec text: leformationmodelcombinedwithGCNandRNNtoper rec score: 0.952401
|
||||
********** end print ocr result **********
|
||||
5 type: title, region: [444,705,564,724], score: 0.785429, res: count of ocr result is : 1
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[6,2],[113,2],[113,14],[6,14]] rec text: 5.Conclusion rec score: 0.856903
|
||||
********** end print ocr result **********
|
||||
6 type: table, region: [14,360,402,711], score: 0.963643, res: <html><body><table><thead><tr><td>Methods</td><td>Ext</td><td>R</td><td>P</td><td>F</td><td>FPS</td></tr></thead><tbody><tr><td>TextSnake [18]</td><td>Syn</td><td>85.3</td><td>67.9</td><td>75.6</td><td></td></tr><tr><td>CSE [17]</td><td>MiLT</td><td>76.1</td><td>78.7</td><td>77.4</td><td>0.38</td></tr><tr><td>LOMO[40]</td><td>Syn</td><td>76.5</td><td>85.7</td><td>80.8</td><td>4.4</td></tr><tr><td>ATRR[35]</td><td>Sy-</td><td>80.2</td><td>80.1</td><td>80.1</td><td>-</td></tr><tr><td>SegLink++ [28]</td><td>Syn</td><td>79.8</td><td>82.8</td><td>81.3</td><td>-</td></tr><tr><td>TextField [37]</td><td>Syn</td><td>79.8</td><td>83.0</td><td>81.4</td><td>6.0</td></tr><tr><td>MSR[38]</td><td>Syn</td><td>79.0</td><td>84.1</td><td>81.5</td><td>4.3</td></tr><tr><td>PSENet-1s [33]</td><td>MLT</td><td>79.7</td><td>84.8</td><td>82.2</td><td>3.9</td></tr><tr><td>DB [12]</td><td>Syn</td><td>80.2</td><td>86.9</td><td>83.4</td><td>22.0</td></tr><tr><td>CRAFT [2]</td><td>Syn</td><td>81.1</td><td>86.0</td><td>83.5</td><td>-</td></tr><tr><td>TextDragon [5]</td><td>MLT+</td><td>82.8</td><td>84.5</td><td>83.6</td><td></td></tr><tr><td>PAN [34]</td><td>Syn</td><td>81.2</td><td>86.4</td><td>83.7</td><td>39.8</td></tr><tr><td>ContourNet [36]</td><td></td><td>84.1</td><td>83.7</td><td>83.9</td><td>4.5</td></tr><tr><td>DRRG [41]</td><td>MLT</td><td>83.02</td><td>85.93</td><td>84.45</td><td>-</td></tr><tr><td>TextPerception[23]</td><td>Syn</td><td>81.9</td><td>87.5</td><td>84.6</td><td></td></tr><tr><td>Ours</td><td> Syn</td><td>80.57</td><td>87.66</td><td>83.97</td><td>12.08</td></tr><tr><td>Ours</td><td></td><td>81.45</td><td>87.81</td><td>84.51</td><td>12.15</td></tr><tr><td>Ours</td><td>MLT</td><td>83.60</td><td>86.45</td><td>85.00</td><td>12.21</td></tr></tbody></table></body></html>
|
||||
The table visualized image saved in ./output//6_1.png
|
||||
7 type: table, region: [462,359,820,657], score: 0.953917, res: <html><body><table><thead><tr><td>Methods</td><td>R</td><td>P</td><td>F</td><td>FPS</td></tr></thead><tbody><tr><td>SegLink [26]</td><td>70.0</td><td>86.0</td><td>77.0</td><td>8.9</td></tr><tr><td>PixelLink [4]</td><td>73.2</td><td>83.0</td><td>77.8</td><td>-</td></tr><tr><td>TextSnake [18]</td><td>73.9</td><td>83.2</td><td>78.3</td><td>1.1</td></tr><tr><td>TextField [37]</td><td>75.9</td><td>87.4</td><td>81.3</td><td>5.2 </td></tr><tr><td>MSR[38]</td><td>76.7</td><td>87.4</td><td>81.7</td><td>-</td></tr><tr><td>FTSN[3]</td><td>77.1</td><td>87.6</td><td>82.0</td><td>:</td></tr><tr><td>LSE[30]</td><td>81.7</td><td>84.2</td><td>82.9</td><td></td></tr><tr><td>CRAFT [2]</td><td>78.2</td><td>88.2</td><td>82.9</td><td>8.6</td></tr><tr><td>MCN [16]</td><td>79</td><td>88</td><td>83</td><td>-</td></tr><tr><td>ATRR[35]</td><td>82.1</td><td>85.2</td><td>83.6</td><td>-</td></tr><tr><td>PAN [34]</td><td>83.8</td><td>84.4</td><td>84.1</td><td>30.2</td></tr><tr><td>DB[12]</td><td>79.2</td><td>91.5</td><td>84.9</td><td>32.0</td></tr><tr><td>DRRG [41]</td><td>82.30</td><td>88.05</td><td>85.08</td><td>-</td></tr><tr><td>Ours (SynText)</td><td>80.68</td><td>85.40</td><td>82.97</td><td>12.68</td></tr><tr><td>Ours (MLT-17)</td><td>84.54</td><td>86.62</td><td>85.57</td><td>12.31</td></tr></tbody></table></body></html>
|
||||
The table visualized image saved in ./output//7_1.png
|
||||
8 type: figure, region: [14,3,836,310], score: 0.969443, res: count of ocr result is : 26
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[506,14],[539,15],[539,22],[506,21]] rec text: E rec score: 0.318073
|
||||
...
|
||||
25 det boxes: [[680,290],[759,288],[759,303],[680,305]] rec text: (d) CTW1500 rec score: 0.95911
|
||||
********** end print ocr result **********
|
||||
```
|
||||
|
||||
## 3. FAQ
|
||||
|
||||
1. Encountered the error `unable to access 'https://github.com/LDOUBLEV/AutoLog.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.`, change the github address in `deploy/cpp_infer/external-cmake/auto-log.cmake` to the <https://gitee.com/Double_V/AutoLog> address.
|
||||
443
docs/version2.x/ppstructure/infer_deploy/cpp_infer.md
Normal file
443
docs/version2.x/ppstructure/infer_deploy/cpp_infer.md
Normal file
@@ -0,0 +1,443 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 服务器端C++预测
|
||||
|
||||
本章节介绍PaddleOCR 模型的C++部署方法。C++在性能计算上优于Python,因此,在大多数CPU、GPU部署场景,多采用C++的部署方式,本节将介绍如何在Linux\Windows (CPU\GPU)环境下配置C++环境并完成PaddleOCR模型部署。
|
||||
|
||||
## 1. 准备环境
|
||||
|
||||
### 1.1 运行准备
|
||||
|
||||
- Linux环境,推荐使用docker。
|
||||
- Windows环境。
|
||||
|
||||
- 该文档主要介绍基于Linux环境的PaddleOCR C++预测流程,如果需要在Windows下基于预测库进行C++预测,具体编译方法请参考[Windows下编译教程](../../ppocr/infer_deploy/windows_vs2019_build.md)
|
||||
|
||||
### 1.2 编译opencv库
|
||||
|
||||
- 首先需要从opencv官网上下载在Linux环境下源码编译的包,以opencv3.4.7为例,下载命令如下:
|
||||
|
||||
```bash linenums="1"
|
||||
cd deploy/cpp_infer
|
||||
wget https://paddleocr.bj.bcebos.com/libs/opencv/opencv-3.4.7.tar.gz
|
||||
tar -xf opencv-3.4.7.tar.gz
|
||||
```
|
||||
|
||||
最终可以在当前目录下看到`opencv-3.4.7/`的文件夹。
|
||||
|
||||
- 编译opencv,设置opencv源码路径(`root_path`)以及安装路径(`install_path`)。进入opencv源码路径下,按照下面的方式进行编译。
|
||||
|
||||
```bash linenums="1"
|
||||
root_path="your_opencv_root_path"
|
||||
install_path=${root_path}/opencv3
|
||||
build_dir=${root_path}/build
|
||||
|
||||
rm -rf ${build_dir}
|
||||
mkdir ${build_dir}
|
||||
cd ${build_dir}
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX=${install_path} \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DWITH_IPP=OFF \
|
||||
-DBUILD_IPP_IW=OFF \
|
||||
-DWITH_LAPACK=OFF \
|
||||
-DWITH_EIGEN=OFF \
|
||||
-DCMAKE_INSTALL_LIBDIR=lib64 \
|
||||
-DWITH_ZLIB=ON \
|
||||
-DBUILD_ZLIB=ON \
|
||||
-DWITH_JPEG=ON \
|
||||
-DBUILD_JPEG=ON \
|
||||
-DWITH_PNG=ON \
|
||||
-DBUILD_PNG=ON \
|
||||
-DWITH_TIFF=ON \
|
||||
-DBUILD_TIFF=ON
|
||||
|
||||
make -j
|
||||
make install
|
||||
```
|
||||
|
||||
也可以直接修改`tools/build_opencv.sh`的内容,然后直接运行下面的命令进行编译。
|
||||
|
||||
```bash linenums="1"
|
||||
sh tools/build_opencv.sh
|
||||
```
|
||||
|
||||
其中`root_path`为下载的opencv源码路径,`install_path`为opencv的安装路径,`make install`完成之后,会在该文件夹下生成opencv头文件和库文件,用于后面的OCR代码编译。
|
||||
|
||||
最终在安装路径下的文件结构如下所示。
|
||||
|
||||
```text linenums="1"
|
||||
opencv3/
|
||||
|-- bin
|
||||
|-- include
|
||||
|-- lib
|
||||
|-- lib64
|
||||
|-- share
|
||||
```
|
||||
|
||||
### 1.3 下载或者编译Paddle预测库
|
||||
|
||||
可以选择直接下载安装或者从源码编译,下文分别进行具体说明。
|
||||
|
||||
#### 1.3.1 直接下载安装
|
||||
|
||||
[Paddle预测库官网](https://www.paddlepaddle.org.cn/inference/master/guides/install/download_lib.html#linux) 上提供了不同cuda版本的Linux预测库,可以在官网查看并选择合适的预测库版本(*建议选择paddle版本>=2.0.1版本的预测库* )。
|
||||
|
||||
下载之后解压:
|
||||
|
||||
```bash linenums="1"
|
||||
tar -xf paddle_inference.tgz
|
||||
```
|
||||
|
||||
最终会在当前的文件夹中生成`paddle_inference/`的子文件夹。
|
||||
|
||||
#### 1.3.2 预测库源码编译
|
||||
|
||||
如果希望获取最新预测库特性,可以从github上克隆最新Paddle代码进行编译,生成最新的预测库。
|
||||
|
||||
- 使用git获取代码:
|
||||
|
||||
```bash linenums="1"
|
||||
git clone https://github.com/PaddlePaddle/Paddle.git
|
||||
git checkout develop
|
||||
```
|
||||
|
||||
- 进入Paddle目录,进行编译:
|
||||
|
||||
```bash linenums="1"
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
cmake .. \
|
||||
-DWITH_CONTRIB=OFF \
|
||||
-DWITH_MKL=ON \
|
||||
-DWITH_MKLDNN=ON \
|
||||
-DWITH_TESTING=OFF \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DWITH_INFERENCE_API_TEST=OFF \
|
||||
-DON_INFER=ON \
|
||||
-DWITH_PYTHON=ON
|
||||
make -j
|
||||
make inference_lib_dist
|
||||
```
|
||||
|
||||
更多编译参数选项介绍可以参考[Paddle预测库编译文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/2.0/guides/05_inference_deployment/inference/build_and_install_lib_cn.html#congyuanmabianyi)。
|
||||
|
||||
- 编译完成之后,可以在`build/paddle_inference_install_dir/`文件下看到生成了以下文件及文件夹。
|
||||
|
||||
```
|
||||
build/paddle_inference_install_dir/
|
||||
|-- CMakeCache.txt
|
||||
|-- paddle
|
||||
|-- third_party
|
||||
|-- version.txt
|
||||
```
|
||||
|
||||
其中`paddle`就是C++预测所需的Paddle库,`version.txt`中包含当前预测库的版本信息。
|
||||
|
||||
## 2. 开始运行
|
||||
|
||||
### 2.1 准备模型
|
||||
|
||||
直接下载PaddleOCR提供的推理模型,或者参考[模型预测章节](../../ppocr/infer_deploy/python_infer.md),将训练好的模型导出为推理模型。模型导出之后,假设放在`inference`目录下,则目录结构如下:
|
||||
|
||||
```text linenums="1"
|
||||
inference/
|
||||
|-- det_db
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
|-- rec_rcnn
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
|-- cls
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
|-- table
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
|-- layout
|
||||
| |--inference.pdiparams
|
||||
| |--inference.pdmodel
|
||||
```
|
||||
|
||||
### 2.2 编译PaddleOCR C++预测demo
|
||||
|
||||
编译命令如下,其中Paddle C++预测库、opencv等其他依赖库的地址需要换成自己机器上的实际地址。
|
||||
|
||||
```bash linenums="1"
|
||||
sh tools/build.sh
|
||||
```
|
||||
|
||||
具体的,需要修改`tools/build.sh`中环境路径,相关内容如下:
|
||||
|
||||
```bash linenums="1"
|
||||
OPENCV_DIR=your_opencv_dir
|
||||
LIB_DIR=your_paddle_inference_dir
|
||||
CUDA_LIB_DIR=your_cuda_lib_dir
|
||||
CUDNN_LIB_DIR=/your_cudnn_lib_dir
|
||||
```
|
||||
|
||||
其中,`OPENCV_DIR`为opencv编译安装的地址;`LIB_DIR`为下载(`paddle_inference`文件夹)或者编译生成的Paddle预测库地址(`build/paddle_inference_install_dir`文件夹);`CUDA_LIB_DIR`为cuda库文件地址,在docker中为`/usr/local/cuda/lib64`;`CUDNN_LIB_DIR`为cudnn库文件地址,在docker中为`/usr/lib/x86_64-linux-gnu/`。**注意:以上路径都写绝对路径,不要写相对路径。**
|
||||
|
||||
编译完成之后,会在`build`文件夹下生成一个名为`ppocr`的可执行文件。
|
||||
|
||||
### 2.3 运行demo
|
||||
|
||||
本demo支持系统串联调用,也支持单个功能的调用,如,只使用检测或识别功能。
|
||||
|
||||
**注意** ppocr默认使用`PP-OCRv3`模型,识别模型使用的输入shape为`3,48,320`, 如需使用旧版本的PP-OCR模型,则需要设置参数`--rec_img_h=32`。
|
||||
|
||||
运行方式:
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr [--param1] [--param2] [...]
|
||||
```
|
||||
|
||||
具体命令如下:
|
||||
|
||||
#### 1. 检测+分类+识别
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--rec_model_dir=inference/rec_rcnn \
|
||||
--cls_model_dir=inference/cls \
|
||||
--image_dir=../../doc/imgs/12.jpg \
|
||||
--use_angle_cls=true \
|
||||
--det=true \
|
||||
--rec=true \
|
||||
--cls=true \
|
||||
```
|
||||
|
||||
##### 2. 检测+识别
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--rec_model_dir=inference/rec_rcnn \
|
||||
--image_dir=../../doc/imgs/12.jpg \
|
||||
--use_angle_cls=false \
|
||||
--det=true \
|
||||
--rec=true \
|
||||
--cls=false \
|
||||
```
|
||||
|
||||
##### 3. 检测
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--image_dir=../../doc/imgs/12.jpg \
|
||||
--det=true \
|
||||
--rec=false
|
||||
```
|
||||
|
||||
##### 4. 分类+识别
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --rec_model_dir=inference/rec_rcnn \
|
||||
--cls_model_dir=inference/cls \
|
||||
--image_dir=../../doc/imgs_words/ch/word_1.jpg \
|
||||
--use_angle_cls=true \
|
||||
--det=false \
|
||||
--rec=true \
|
||||
--cls=true \
|
||||
```
|
||||
|
||||
##### 5. 识别
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --rec_model_dir=inference/rec_rcnn \
|
||||
--image_dir=../../doc/imgs_words/ch/word_1.jpg \
|
||||
--use_angle_cls=false \
|
||||
--det=false \
|
||||
--rec=true \
|
||||
--cls=false \
|
||||
```
|
||||
|
||||
##### 6. 分类
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --cls_model_dir=inference/cls \
|
||||
--cls_model_dir=inference/cls \
|
||||
--image_dir=../../doc/imgs_words/ch/word_1.jpg \
|
||||
--use_angle_cls=true \
|
||||
--det=false \
|
||||
--rec=false \
|
||||
--cls=true \
|
||||
```
|
||||
|
||||
##### 7. 版面分析+表格识别
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--rec_model_dir=inference/rec_rcnn \
|
||||
--table_model_dir=inference/table \
|
||||
--image_dir=../../ppstructure/docs/table/table.jpg \
|
||||
--layout_model_dir=inference/layout \
|
||||
--type=structure \
|
||||
--table=true \
|
||||
--layout=true
|
||||
```
|
||||
|
||||
##### 8. 版面分析
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --layout_model_dir=inference/layout \
|
||||
--image_dir=../../ppstructure/docs/table/1.png \
|
||||
--type=structure \
|
||||
--table=false \
|
||||
--layout=true \
|
||||
--det=false \
|
||||
--rec=false
|
||||
```
|
||||
|
||||
##### 9. 表格识别
|
||||
|
||||
```bash linenums="1"
|
||||
./build/ppocr --det_model_dir=inference/det_db \
|
||||
--rec_model_dir=inference/rec_rcnn \
|
||||
--table_model_dir=inference/table \
|
||||
--image_dir=../../ppstructure/docs/table/table.jpg \
|
||||
--type=structure \
|
||||
--table=true
|
||||
```
|
||||
|
||||
更多支持的可调节参数解释如下:
|
||||
|
||||
- 通用参数
|
||||
|
||||
| 参数名称 | 类型 | 默认参数 | 意义 |
|
||||
| :--------------------------: | :---: | :------: | :---------------------------------------------------------------: |
|
||||
| use_gpu | bool | false | 是否使用GPU |
|
||||
| gpu_id | int | 0 | GPU id,使用GPU时有效 |
|
||||
| gpu_mem | int | 4000 | 申请的GPU内存 |
|
||||
| cpu_math_library_num_threads | int | 10 | CPU预测时的线程数,在机器核数充足的情况下,该值越大,预测速度越快 |
|
||||
| enable_mkldnn | bool | true | 是否使用mkldnn库 |
|
||||
| output | str | ./output | 可视化结果保存的路径 |
|
||||
|
||||
- 前向相关
|
||||
|
||||
| 参数名称 | 类型 | 默认参数 | 意义 |
|
||||
| :------: | :---: | :------: | :----------------------: |
|
||||
| det | bool | true | 前向是否执行文字检测 |
|
||||
| rec | bool | true | 前向是否执行文字识别 |
|
||||
| cls | bool | false | 前向是否执行文字方向分类 |
|
||||
|
||||
- 检测模型相关
|
||||
|
||||
| 参数名称 | 类型 | 默认参数 | 意义 |
|
||||
| :-----------------: | :----: | :------: | :----------------------------------------------------------------------------------------------------------: |
|
||||
| det_model_dir | string | - | 检测模型inference model地址 |
|
||||
| max_side_len | int | 960 | 输入图像长宽大于960时,等比例缩放图像,使得图像最长边为960 |
|
||||
| det_db_thresh | float | 0.3 | 用于过滤DB预测的二值化图像,设置为0.-0.3对结果影响不明显 |
|
||||
| det_db_box_thresh | float | 0.5 | DB后处理过滤box的阈值,如果检测存在漏框情况,可酌情减小 |
|
||||
| det_db_unclip_ratio | float | 1.6 | 表示文本框的紧致程度,越小则文本框更靠近文本 |
|
||||
| det_db_score_mode | string | slow | slow:使用多边形框计算bbox score,fast:使用矩形框计算。矩形框计算速度更快,多边形框对弯曲文本区域计算更准确。 |
|
||||
| visualize | bool | true | 是否对结果进行可视化,为1时,预测结果会保存在`output`字段指定的文件夹下和输入图像同名的图像上。 |
|
||||
|
||||
- 方向分类器相关
|
||||
|
||||
| 参数名称 | 类型 | 默认参数 | 意义 |
|
||||
| :-----------: | :----: | :------: | :---------------------------: |
|
||||
| use_angle_cls | bool | false | 是否使用方向分类器 |
|
||||
| cls_model_dir | string | - | 方向分类器inference model地址 |
|
||||
| cls_thresh | float | 0.9 | 方向分类器的得分阈值 |
|
||||
| cls_batch_num | int | 1 | 方向分类器batchsize |
|
||||
|
||||
- 文字识别模型相关
|
||||
|
||||
| 参数名称 | 类型 | 默认参数 | 意义 |
|
||||
| :----------------: | :----: | :---------------------------------: | :-----------------------------: |
|
||||
| rec_model_dir | string | - | 文字识别模型inference model地址 |
|
||||
| rec_char_dict_path | string | ../../ppocr/utils/ppocr_keys_v1.txt | 字典文件 |
|
||||
| rec_batch_num | int | 6 | 文字识别模型batchsize |
|
||||
| rec_img_h | int | 48 | 文字识别模型输入图像高度 |
|
||||
| rec_img_w | int | 320 | 文字识别模型输入图像宽度 |
|
||||
|
||||
- 版面分析模型相关
|
||||
|
||||
| 参数名称 | 类型 | 默认参数 | 意义 |
|
||||
| :--------------------: | :----: | :----------------------------------------------------------: | :-----------------------------: |
|
||||
| layout_model_dir | string | - | 版面分析模型inference model地址 |
|
||||
| layout_dict_path | string | ../../ppocr/utils/dict/layout_dict/layout_publaynet_dict.txt | 字典文件 |
|
||||
| layout_score_threshold | float | 0.5 | 检测框的分数阈值 |
|
||||
| layout_nms_threshold | float | 0.5 | nms的阈值 |
|
||||
|
||||
- 表格识别模型相关
|
||||
|
||||
| 参数名称 | 类型 | 默认参数 | 意义 |
|
||||
| :---------------------: | :----: | :------------------------------------------------: | :----------------------------------------------------------------------------------: |
|
||||
| table_model_dir | string | - | 表格识别模型inference model地址 |
|
||||
| table_char_dict_path | string | ../../ppocr/utils/dict/table_structure_dict_ch.txt | 字典文件 |
|
||||
| table_max_len | int | 488 | 表格识别模型输入图像长边大小,最终网络输入图像大小为(table_max_len,table_max_len) |
|
||||
| merge_no_span_structure | bool | true | 是否合并<td> 和 </td> 为<td></td> |
|
||||
|
||||
- PaddleOCR也支持多语言的预测,更多支持的语言和模型可以参考[识别文档](../../ppocr/blog/multi_languages.md)中的多语言字典与模型部分,如果希望进行多语言预测,只需将修改`rec_char_dict_path`(字典文件路径)以及`rec_model_dir`(inference模型路径)字段即可。
|
||||
|
||||
最终屏幕上会输出检测结果如下:
|
||||
|
||||
- ocr
|
||||
|
||||
```bash linenums="1"
|
||||
predict img: ../../doc/imgs/12.jpg
|
||||
../../doc/imgs/12.jpg
|
||||
0 det boxes: [[74,553],[427,542],[428,571],[75,582]] rec text: 打浦路252935号 rec score: 0.947724
|
||||
1 det boxes: [[23,507],[513,488],[515,529],[24,548]] rec text: 绿洲仕格维花园公寓 rec score: 0.993728
|
||||
2 det boxes: [[187,456],[399,448],[400,480],[188,488]] rec text: 打浦路15号 rec score: 0.964994
|
||||
3 det boxes: [[42,413],[483,391],[484,428],[43,450]] rec text: 上海斯格威铂尔大酒店 rec score: 0.980086
|
||||
The detection visualized image saved in ./output//12.jpg
|
||||
```
|
||||
|
||||
- layout+table
|
||||
|
||||
```bash linenums="1"
|
||||
predict img: ../../ppstructure/docs/table/1.png
|
||||
0 type: text, region: [12,729,410,848], score: 0.781044, res: count of ocr result is : 7
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[4,1],[79,1],[79,12],[4,12]] rec text: CTW1500. rec score: 0.769472
|
||||
...
|
||||
6 det boxes: [[4,99],[391,99],[391,112],[4,112]] rec text: sate-of-the-artmethods[12.34.36l.ourapproachachieves rec score: 0.90414
|
||||
********** end print ocr result **********
|
||||
1 type: text, region: [69,342,342,359], score: 0.703666, res: count of ocr result is : 1
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[8,2],[269,2],[269,13],[8,13]] rec text: Table6.Experimentalresults on CTW-1500 rec score: 0.890454
|
||||
********** end print ocr result **********
|
||||
2 type: text, region: [70,316,706,332], score: 0.659738, res: count of ocr result is : 2
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[373,2],[630,2],[630,11],[373,11]] rec text: oroposals.andthegreencontoursarefinal rec score: 0.919729
|
||||
1 det boxes: [[8,3],[357,3],[357,11],[8,11]] rec text: Visualexperimentalresultshebluecontoursareboundar rec score: 0.915963
|
||||
********** end print ocr result **********
|
||||
3 type: text, region: [489,342,789,359], score: 0.630538, res: count of ocr result is : 1
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[8,2],[294,2],[294,14],[8,14]] rec text: Table7.Experimentalresults onMSRA-TD500 rec score: 0.942251
|
||||
********** end print ocr result **********
|
||||
4 type: text, region: [444,751,841,848], score: 0.607345, res: count of ocr result is : 5
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[19,3],[389,3],[389,17],[19,17]] rec text: Inthispaper,weproposeanovel adaptivebound rec score: 0.941031
|
||||
1 det boxes: [[4,22],[390,22],[390,36],[4,36]] rec text: aryproposalnetworkforarbitraryshapetextdetection rec score: 0.960172
|
||||
2 det boxes: [[4,42],[392,42],[392,56],[4,56]] rec text: whichadoptanboundaryproposalmodeltogeneratecoarse rec score: 0.934647
|
||||
3 det boxes: [[4,61],[389,61],[389,75],[4,75]] rec text: ooundaryproposals,andthenadoptanadaptiveboundary rec score: 0.946296
|
||||
4 det boxes: [[5,80],[387,80],[387,93],[5,93]] rec text: leformationmodelcombinedwithGCNandRNNtoper rec score: 0.952401
|
||||
********** end print ocr result **********
|
||||
5 type: title, region: [444,705,564,724], score: 0.785429, res: count of ocr result is : 1
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[6,2],[113,2],[113,14],[6,14]] rec text: 5.Conclusion rec score: 0.856903
|
||||
********** end print ocr result **********
|
||||
6 type: table, region: [14,360,402,711], score: 0.963643, res: <html><body><table><thead><tr><td>Methods</td><td>Ext</td><td>R</td><td>P</td><td>F</td><td>FPS</td></tr></thead><tbody><tr><td>TextSnake [18]</td><td>Syn</td><td>85.3</td><td>67.9</td><td>75.6</td><td></td></tr><tr><td>CSE [17]</td><td>MiLT</td><td>76.1</td><td>78.7</td><td>77.4</td><td>0.38</td></tr><tr><td>LOMO[40]</td><td>Syn</td><td>76.5</td><td>85.7</td><td>80.8</td><td>4.4</td></tr><tr><td>ATRR[35]</td><td>Sy-</td><td>80.2</td><td>80.1</td><td>80.1</td><td>-</td></tr><tr><td>SegLink++ [28]</td><td>Syn</td><td>79.8</td><td>82.8</td><td>81.3</td><td>-</td></tr><tr><td>TextField [37]</td><td>Syn</td><td>79.8</td><td>83.0</td><td>81.4</td><td>6.0</td></tr><tr><td>MSR[38]</td><td>Syn</td><td>79.0</td><td>84.1</td><td>81.5</td><td>4.3</td></tr><tr><td>PSENet-1s [33]</td><td>MLT</td><td>79.7</td><td>84.8</td><td>82.2</td><td>3.9</td></tr><tr><td>DB [12]</td><td>Syn</td><td>80.2</td><td>86.9</td><td>83.4</td><td>22.0</td></tr><tr><td>CRAFT [2]</td><td>Syn</td><td>81.1</td><td>86.0</td><td>83.5</td><td>-</td></tr><tr><td>TextDragon [5]</td><td>MLT+</td><td>82.8</td><td>84.5</td><td>83.6</td><td></td></tr><tr><td>PAN [34]</td><td>Syn</td><td>81.2</td><td>86.4</td><td>83.7</td><td>39.8</td></tr><tr><td>ContourNet [36]</td><td></td><td>84.1</td><td>83.7</td><td>83.9</td><td>4.5</td></tr><tr><td>DRRG [41]</td><td>MLT</td><td>83.02</td><td>85.93</td><td>84.45</td><td>-</td></tr><tr><td>TextPerception[23]</td><td>Syn</td><td>81.9</td><td>87.5</td><td>84.6</td><td></td></tr><tr><td>Ours</td><td> Syn</td><td>80.57</td><td>87.66</td><td>83.97</td><td>12.08</td></tr><tr><td>Ours</td><td></td><td>81.45</td><td>87.81</td><td>84.51</td><td>12.15</td></tr><tr><td>Ours</td><td>MLT</td><td>83.60</td><td>86.45</td><td>85.00</td><td>12.21</td></tr></tbody></table></body></html>
|
||||
The table visualized image saved in ./output//6_1.png
|
||||
7 type: table, region: [462,359,820,657], score: 0.953917, res: <html><body><table><thead><tr><td>Methods</td><td>R</td><td>P</td><td>F</td><td>FPS</td></tr></thead><tbody><tr><td>SegLink [26]</td><td>70.0</td><td>86.0</td><td>77.0</td><td>8.9</td></tr><tr><td>PixelLink [4]</td><td>73.2</td><td>83.0</td><td>77.8</td><td>-</td></tr><tr><td>TextSnake [18]</td><td>73.9</td><td>83.2</td><td>78.3</td><td>1.1</td></tr><tr><td>TextField [37]</td><td>75.9</td><td>87.4</td><td>81.3</td><td>5.2 </td></tr><tr><td>MSR[38]</td><td>76.7</td><td>87.4</td><td>81.7</td><td>-</td></tr><tr><td>FTSN[3]</td><td>77.1</td><td>87.6</td><td>82.0</td><td>:</td></tr><tr><td>LSE[30]</td><td>81.7</td><td>84.2</td><td>82.9</td><td></td></tr><tr><td>CRAFT [2]</td><td>78.2</td><td>88.2</td><td>82.9</td><td>8.6</td></tr><tr><td>MCN [16]</td><td>79</td><td>88</td><td>83</td><td>-</td></tr><tr><td>ATRR[35]</td><td>82.1</td><td>85.2</td><td>83.6</td><td>-</td></tr><tr><td>PAN [34]</td><td>83.8</td><td>84.4</td><td>84.1</td><td>30.2</td></tr><tr><td>DB[12]</td><td>79.2</td><td>91.5</td><td>84.9</td><td>32.0</td></tr><tr><td>DRRG [41]</td><td>82.30</td><td>88.05</td><td>85.08</td><td>-</td></tr><tr><td>Ours (SynText)</td><td>80.68</td><td>85.40</td><td>82.97</td><td>12.68</td></tr><tr><td>Ours (MLT-17)</td><td>84.54</td><td>86.62</td><td>85.57</td><td>12.31</td></tr></tbody></table></body></html>
|
||||
The table visualized image saved in ./output//7_1.png
|
||||
8 type: figure, region: [14,3,836,310], score: 0.969443, res: count of ocr result is : 26
|
||||
********** print ocr result **********
|
||||
0 det boxes: [[506,14],[539,15],[539,22],[506,21]] rec text: E rec score: 0.318073
|
||||
...
|
||||
25 det boxes: [[680,290],[759,288],[759,303],[680,305]] rec text: (d) CTW1500 rec score: 0.95911
|
||||
********** end print ocr result **********
|
||||
```
|
||||
|
||||
## 3. FAQ
|
||||
|
||||
1. 遇到报错 `unable to access 'https://github.com/LDOUBLEV/AutoLog.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.`, 将 `deploy/cpp_infer/external-cmake/auto-log.cmake` 中的github地址改为 <https://gitee.com/Double_V/AutoLog> 地址即可。
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 992 KiB |
21
docs/version2.x/ppstructure/infer_deploy/index.en.md
Normal file
21
docs/version2.x/ppstructure/infer_deploy/index.en.md
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# PP-OCR Deployment
|
||||
|
||||
## Paddle Deployment Introduction
|
||||
|
||||
Paddle provides a variety of deployment schemes to meet the deployment requirements of different scenarios. Please choose according to the actual situation:
|
||||
|
||||

|
||||
|
||||
PP-OCR has supported multi deployment schemes. Click the link to get the specific tutorial.
|
||||
|
||||
- [Python Inference](./python_infer.en.md)
|
||||
- [C++ Inference](./cpp_infer.en.md)
|
||||
- [Serving (Python/C++)](./paddle_server.en.md)
|
||||
- [Paddle-Lite (ARM CPU/OpenCL ARM GPU)](../../ppocr/infer_deploy/lite.en.md)
|
||||
- [Paddle2ONNX](../../ppocr/infer_deploy/paddle2onnx.en.md)
|
||||
|
||||
If you need the deployment tutorial of academic algorithm models other than PP-OCR, please directly enter the main page of corresponding algorithms, [entrance](../../algorithm/overview.en.md)。
|
||||
24
docs/version2.x/ppstructure/infer_deploy/index.md
Normal file
24
docs/version2.x/ppstructure/infer_deploy/index.md
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
typora-copy-images-to: images
|
||||
comments: true
|
||||
---
|
||||
|
||||
# PP-OCR 模型推理部署
|
||||
|
||||
## Paddle 推理部署方式简介
|
||||
|
||||
飞桨提供多种部署方案,以满足不同场景的部署需求,请根据实际情况进行选择:
|
||||
|
||||

|
||||
|
||||
## PP-OCR 推理部署
|
||||
|
||||
PP-OCR模型已打通多种场景部署方案,点击链接获取具体的使用教程。
|
||||
|
||||
- [Python 推理](./python_infer.md)
|
||||
- [C++ 推理](./cpp_infer.md)
|
||||
- [Serving 服务化部署(Python/C++)](./paddle_server.md)
|
||||
- [Paddle-Lite 端侧部署(ARM CPU/OpenCL ARM GPU)](../../ppocr/infer_deploy/lite.md)
|
||||
- [Paddle2ONNX 推理](../../ppocr/infer_deploy/paddle2onnx.md)
|
||||
|
||||
需要PP-OCR以外的学术算法模型的推理部署,请直接进入相应算法主页面,[入口](../../algorithm/overview.md)。
|
||||
273
docs/version2.x/ppstructure/infer_deploy/paddle_server.en.md
Executable file
273
docs/version2.x/ppstructure/infer_deploy/paddle_server.en.md
Executable file
@@ -0,0 +1,273 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
PaddleOCR provides 2 service deployment methods:
|
||||
|
||||
- Based on **PaddleHub Serving**: Code path is `./deploy/hubserving`. Please follow this tutorial.
|
||||
- Based on **PaddleServing**: Code path is `./deploy/pdserving`. Please refer to the [tutorial](../../ppocr/infer_deploy/paddle_server.en.md) for usage.
|
||||
|
||||
# Service deployment based on PaddleHub Serving
|
||||
|
||||
The hubserving service deployment directory includes seven service packages: text detection, text angle class, text recognition, text detection+text angle class+text recognition three-stage series connection, layout analysis, table recognition, and PP-Structure. Please select the corresponding service package to install and start the service according to your needs. The directory is as follows:
|
||||
|
||||
```text linenums="1"
|
||||
deploy/hubserving/
|
||||
└─ ocr_det text detection module service package
|
||||
└─ ocr_cls text angle class module service package
|
||||
└─ ocr_rec text recognition module service package
|
||||
└─ ocr_system text detection+text angle class+text recognition three-stage series connection service package
|
||||
└─ structure_layout layout analysis service package
|
||||
└─ structure_table table recognition service package
|
||||
└─ structure_system PP-Structure service package
|
||||
└─ kie_ser KIE(SER) service package
|
||||
└─ kie_ser_re KIE(SER+RE) service package
|
||||
```
|
||||
|
||||
Each service pack contains 3 files. Take the 2-stage series connection service package as an example, the directory is as follows:
|
||||
|
||||
```text linenums="1"
|
||||
deploy/hubserving/ocr_system/
|
||||
└─ __init__.py Empty file, required
|
||||
└─ config.json Configuration file, optional, passed in as a parameter when using configuration to start the service
|
||||
└─ module.py Main module file, required, contains the complete logic of the service
|
||||
└─ params.py Parameter file, required, including parameters such as model path, pre and post-processing parameters
|
||||
```
|
||||
|
||||
## 1. Update
|
||||
|
||||
- 2022.10.09 add KIE services.
|
||||
- 2022.08.23 add layout analysis services.
|
||||
- 2022.03.30 add PP-Structure and table recognition services.
|
||||
- 2022.05.05 add PP-OCRv3 text detection and recognition services.
|
||||
|
||||
## 2. Quick start service
|
||||
|
||||
The following steps take the 2-stage series service as an example. If only the detection service or recognition service is needed, replace the corresponding file path.
|
||||
|
||||
### 2.1 Install PaddleHub
|
||||
|
||||
```bash linenums="1"
|
||||
pip3 install paddlehub==2.1.0 --upgrade
|
||||
```
|
||||
|
||||
### 2.2 Download inference model
|
||||
|
||||
Before installing the service module, you need to prepare the inference model and put it in the correct path. By default, the PP-OCRv3 models are used, and the default model path is:
|
||||
|
||||
| Model | Path |
|
||||
| ------- | - |
|
||||
| text detection model | ./inference/PP-OCRv3_mobile_det_infer/ |
|
||||
| text recognition model | ./inference/PP-OCRv3_mobile_rec_infer/ |
|
||||
| text angle classifier | ./inference/ch_ppocr_mobile_v2.0_cls_infer/ |
|
||||
| layout parse model | ./inference/picodet_lcnet_x1_0_fgd_layout_infer/ |
|
||||
| tanle recognition | ./inference/ch_ppstructure_mobile_v2.0_SLANet_infer/ |
|
||||
| KIE(SER) | ./inference/ser_vi_layoutxlm_xfund_infer/ |
|
||||
| KIE(SER+RE) | ./inference/re_vi_layoutxlm_xfund_infer/ |
|
||||
|
||||
**The model path can be found and modified in `params.py`.**
|
||||
More models provided by PaddleOCR can be obtained from the [model library](../../ppocr/model_list.en.md). You can also use models trained by yourself.
|
||||
|
||||
### 2.3 Install Service Module
|
||||
|
||||
PaddleOCR provides 5 kinds of service modules, install the required modules according to your needs.
|
||||
|
||||
- On the Linux platform(replace `/` with `\` if using Windows), the examples are as the following table:
|
||||
|
||||
| Service model | Command |
|
||||
| text detection | `hub install deploy/hubserving/ocr_det` |
|
||||
| text angle class: | `hub install deploy/hubserving/ocr_cls` |
|
||||
| text recognition: | `hub install deploy/hubserving/ocr_rec` |
|
||||
| 2-stage series: | `hub install deploy/hubserving/ocr_system` |
|
||||
| table recognition | `hub install deploy/hubserving/structure_table` |
|
||||
| PP-Structure | `hub install deploy/hubserving/structure_system` |
|
||||
| KIE(SER) | `hub install deploy/hubserving/kie_ser` |
|
||||
| KIE(SER+RE) | `hub install deploy/hubserving/kie_ser_re` |
|
||||
|
||||
### 2.4 Start service
|
||||
|
||||
#### 2.4.1 Start with command line parameters (CPU only)
|
||||
|
||||
**start command:**
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving start --modules Module1==Version1, Module2==Version2, ... \
|
||||
--port 8866 \
|
||||
--use_multiprocess \
|
||||
--workers \
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
|parameters|usage|
|
||||
|---|---|
|
||||
|`--modules`/`-m`|PaddleHub Serving pre-installed model, listed in the form of multiple Module==Version key-value pairs<br>**When Version is not specified, the latest version is selected by default**|
|
||||
|`--port`/`-p`|Service port, default is 8866|
|
||||
|`--use_multiprocess`|Enable concurrent mode, by default using the single-process mode, this mode is recommended for multi-core CPU machines<br>**Windows operating system only supports single-process mode**|
|
||||
|`--workers`|The number of concurrent tasks specified in concurrent mode, the default is `2*cpu_count-1`, where `cpu_count` is the number of CPU cores|
|
||||
|
||||
For example, start the 2-stage series service:
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving start -m ocr_system
|
||||
```
|
||||
|
||||
This completes the deployment of a service API, using the default port number 8866.
|
||||
|
||||
#### 2.4.2 Start with configuration file(CPU and GPU)
|
||||
|
||||
**start command:**
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving start --config/-c config.json
|
||||
```
|
||||
|
||||
In which the format of `config.json` is as follows:
|
||||
|
||||
```json
|
||||
{
|
||||
"modules_info": {
|
||||
"ocr_system": {
|
||||
"init_args": {
|
||||
"version": "1.0.0",
|
||||
"use_gpu": true
|
||||
},
|
||||
"predict_args": {
|
||||
}
|
||||
}
|
||||
},
|
||||
"port": 8868,
|
||||
"use_multiprocess": false,
|
||||
"workers": 2
|
||||
}
|
||||
```
|
||||
|
||||
- The configurable parameters in `init_args` are consistent with the `_initialize` function interface in `module.py`.
|
||||
|
||||
**When `use_gpu` is `true`, it means that the GPU is used to start the service**.
|
||||
- The configurable parameters in `predict_args` are consistent with the `predict` function interface in `module.py`.
|
||||
|
||||
**Note:**
|
||||
- When using the configuration file to start the service, other parameters will be ignored.
|
||||
- If you use GPU prediction (that is, `use_gpu` is set to `true`), you need to set the environment variable CUDA_VISIBLE_DEVICES before starting the service, such as:
|
||||
|
||||
```bash linenums="1"
|
||||
export CUDA_VISIBLE_DEVICES=0
|
||||
```
|
||||
|
||||
- **`use_gpu` and `use_multiprocess` cannot be `true` at the same time.**
|
||||
|
||||
For example, use GPU card No. 3 to start the 2-stage series service:
|
||||
|
||||
```bash linenums="1"
|
||||
export CUDA_VISIBLE_DEVICES=3
|
||||
hub serving start -c deploy/hubserving/ocr_system/config.json
|
||||
```
|
||||
|
||||
## 3. Send prediction requests
|
||||
|
||||
After the service starts, you can use the following command to send a prediction request to obtain the prediction result:
|
||||
|
||||
```bash linenums="1"
|
||||
python tools/test_hubserving.py --server_url=server_url --image_dir=image_path
|
||||
```
|
||||
|
||||
Two parameters need to be passed to the script:
|
||||
|
||||
- **server_url**:service address, the format of which is
|
||||
`http://[ip_address]:[port]/predict/[module_name]`
|
||||
|
||||
For example, if using the configuration file to start the text angle classification, text detection, text recognition, detection+classification+recognition 3 stages, table recognition and PP-Structure service,
|
||||
|
||||
also modified the port for each service, then the `server_url` to send the request will be:
|
||||
|
||||
```text linenums="1"
|
||||
http://127.0.0.1:8865/predict/ocr_det
|
||||
http://127.0.0.1:8866/predict/ocr_cls
|
||||
http://127.0.0.1:8867/predict/ocr_rec
|
||||
http://127.0.0.1:8868/predict/ocr_system
|
||||
http://127.0.0.1:8869/predict/structure_table
|
||||
http://127.0.0.1:8870/predict/structure_system
|
||||
http://127.0.0.1:8870/predict/structure_layout
|
||||
http://127.0.0.1:8871/predict/kie_ser
|
||||
http://127.0.0.1:8872/predict/kie_ser_re
|
||||
```
|
||||
|
||||
- **image_dir**:Test image path, which can be a single image path or an image directory path
|
||||
- **visualize**:Whether to visualize the results, the default value is False
|
||||
- **output**:The folder to save the Visualization result, the default value is `./hubserving_result`
|
||||
|
||||
Example:
|
||||
|
||||
```bash linenums="1"
|
||||
python tools/test_hubserving.py --server_url=http://127.0.0.1:8868/predict/ocr_system --image_dir=./doc/imgs/ --visualize=false`
|
||||
```
|
||||
|
||||
## 4. Returned result format
|
||||
|
||||
The returned result is a list. Each item in the list is a dictionary which may contain three fields. The information is as follows:
|
||||
|
||||
|field name|data type|description|
|
||||
|----|----|----|
|
||||
|angle|str|angle|
|
||||
|text|str|text content|
|
||||
|confidence|float|text recognition confidence|
|
||||
|text_region|list|text location coordinates|
|
||||
|html|str|table HTML string|
|
||||
|regions|list|The result of layout analysis + table recognition + OCR, each item is a list<br>including `bbox` indicating area coordinates, `type` of area type and `res` of area results|
|
||||
|layout|list|The result of layout analysis, each item is a dict, including `bbox` indicating area coordinates, `label` of area type|
|
||||
|
||||
The fields returned by different modules are different. For example, the results returned by the text recognition service module do not contain `text_region`, detailed table is as follows:
|
||||
|
||||
|field name/module name |ocr_det |ocr_cls |ocr_rec |ocr_system |structure_table |structure_system |structure_layout |kie_ser |kie_re |
|
||||
|--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |
|
||||
|angle | |✔ | |✔ | | | |
|
||||
|text | | |✔ |✔ | |✔ | |✔ |✔ |
|
||||
|confidence | |✔ |✔ |✔ | |✔ | |✔ |✔ |
|
||||
|text_region |✔ | | |✔ | |✔ | |✔ |✔ |
|
||||
|html | | | | |✔ |✔ | | | |
|
||||
|regions | | | | |✔ |✔ | | | |
|
||||
|layout | | | | | | |✔ | | |
|
||||
|ser_res | | | | | | | |✔ | |
|
||||
|re_res | | | | | | | | |✔ |
|
||||
|
||||
**Note:** If you need to add, delete or modify the returned fields, you can modify the file `module.py` of the corresponding module. For the complete process, refer to the user-defined modification service module in the next section.
|
||||
|
||||
## 5. User-defined service module modification
|
||||
|
||||
If you need to modify the service logic, the following steps are generally required (take the modification of `deploy/hubserving/ocr_system` for example):
|
||||
|
||||
1. Stop service:
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving stop --port/-p XXXX
|
||||
```
|
||||
|
||||
2. Modify the code in the corresponding files under `deploy/hubserving/ocr_system`, such as `module.py` and `params.py`, to your actual needs.
|
||||
|
||||
For example, if you need to replace the model used by the deployed service, you need to modify model path parameters `det_model_dir` and `rec_model_dir` in `params.py`. If you want to turn off the text direction classifier, set the parameter `use_angle_cls` to `False`.
|
||||
|
||||
Of course, other related parameters may need to be modified at the same time. Please modify and debug according to the actual situation.
|
||||
|
||||
**It is suggested to run `module.py` directly for debugging after modification before starting the service test.**
|
||||
|
||||
**Note** The image input shape used by the PPOCR-v3 recognition model is `3, 48, 320`, so you need to modify `cfg.rec_image_shape = "3, 48, 320"` in `params.py`, if you do not use the PPOCR-v3 recognition model, then there is no need to modify this parameter.
|
||||
3. (Optional) If you want to rename the module, the following lines should be modified:
|
||||
- [`ocr_system` within `from deploy.hubserving.ocr_system.params import read_params`](https://github.com/PaddlePaddle/PaddleOCR/blob/a923f35de57b5e378f8dd16e54d0a3e4f51267fd/deploy/hubserving/ocr_system/module.py#L35)
|
||||
- [`ocr_system` within `name="ocr_system",`](https://github.com/PaddlePaddle/PaddleOCR/blob/a923f35de57b5e378f8dd16e54d0a3e4f51267fd/deploy/hubserving/ocr_system/module.py#L39)
|
||||
4. (Optional) It may require you to delete the directory `__pycache__` to force flush build cache of CPython:
|
||||
|
||||
```bash linenums="1"
|
||||
find deploy/hubserving/ocr_system -name '__pycache__' -exec rm -r {} \;
|
||||
```
|
||||
|
||||
5. Install modified service module:
|
||||
|
||||
```bash linenums="1"
|
||||
hub install deploy/hubserving/ocr_system/
|
||||
```
|
||||
|
||||
6. Restart service:
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving start -m ocr_system
|
||||
```
|
||||
279
docs/version2.x/ppstructure/infer_deploy/paddle_server.md
Normal file
279
docs/version2.x/ppstructure/infer_deploy/paddle_server.md
Normal file
@@ -0,0 +1,279 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
PaddleOCR提供2种服务部署方式:
|
||||
|
||||
- 基于PaddleHub Serving的部署:代码路径为`./deploy/hubserving`,按照本教程使用;
|
||||
- 基于PaddleServing的部署:代码路径为`./deploy/pdserving`,使用方法参考[文档](../../ppocr/infer_deploy/paddle_server.md)。
|
||||
|
||||
# 基于PaddleHub Serving的服务部署
|
||||
|
||||
hubserving服务部署目录下包括文本检测、文本方向分类,文本识别、文本检测+文本方向分类+文本识别3阶段串联,版面分析、表格识别和PP-Structure七种服务包,请根据需求选择相应的服务包进行安装和启动。目录结构如下:
|
||||
|
||||
```text linenums="1"
|
||||
deploy/hubserving/
|
||||
└─ ocr_cls 文本方向分类模块服务包
|
||||
└─ ocr_det 文本检测模块服务包
|
||||
└─ ocr_rec 文本识别模块服务包
|
||||
└─ ocr_system 文本检测+文本方向分类+文本识别串联服务包
|
||||
└─ structure_layout 版面分析服务包
|
||||
└─ structure_table 表格识别服务包
|
||||
└─ structure_system PP-Structure服务包
|
||||
└─ kie_ser 关键信息抽取-SER服务包
|
||||
└─ kie_ser_re 关键信息抽取-SER+RE服务包
|
||||
```
|
||||
|
||||
每个服务包下包含3个文件。以2阶段串联服务包为例,目录如下:
|
||||
|
||||
```text linenums="1"
|
||||
deploy/hubserving/ocr_system/
|
||||
└─ __init__.py 空文件,必选
|
||||
└─ config.json 配置文件,可选,使用配置启动服务时作为参数传入
|
||||
└─ module.py 主模块,必选,包含服务的完整逻辑
|
||||
└─ params.py 参数文件,必选,包含模型路径、前后处理参数等参数
|
||||
```
|
||||
|
||||
## 1. 近期更新
|
||||
|
||||
- 2022.10.09 新增关键信息抽取服务。
|
||||
- 2022.08.23 新增版面分析服务。
|
||||
- 2022.05.05 新增PP-OCRv3检测和识别模型。
|
||||
- 2022.03.30 新增PP-Structure和表格识别两种服务。
|
||||
|
||||
## 2. 快速启动服务
|
||||
|
||||
以下步骤以检测+识别2阶段串联服务为例,如果只需要检测服务或识别服务,替换相应文件路径即可。
|
||||
|
||||
### 2.1 安装PaddleHub
|
||||
|
||||
paddlehub 需要 python>3.6.2
|
||||
|
||||
```bash linenums="1"
|
||||
pip3 install paddlehub==2.1.0 --upgrade -i https://mirror.baidu.com/pypi/simple
|
||||
```
|
||||
|
||||
### 2.2 下载推理模型
|
||||
|
||||
安装服务模块前,需要准备推理模型并放到正确路径。默认使用的是PP-OCRv3模型,默认模型路径为:
|
||||
|
||||
| 模型 | 路径 |
|
||||
| ------------------- | ------------------------------------------------------ |
|
||||
| 检测模型 | `./inference/PP-OCRv3_mobile_det_infer/` |
|
||||
| 识别模型 | `./inference/PP-OCRv3_mobile_rec_infer/` |
|
||||
| 方向分类器 | `./inference/ch_ppocr_mobile_v2.0_cls_infer/` |
|
||||
| 版面分析模型 | `./inference/picodet_lcnet_x1_0_fgd_layout_infer/` |
|
||||
| 表格结构识别模型 | `./inference/ch_ppstructure_mobile_v2.0_SLANet_infer/` |
|
||||
| 关键信息抽取SER模型 | `./inference/ser_vi_layoutxlm_xfund_infer/` |
|
||||
| 关键信息抽取RE模型 | `./inference/re_vi_layoutxlm_xfund_infer/` |
|
||||
|
||||
**模型路径可在`params.py`中查看和修改。**
|
||||
|
||||
更多模型可以从PaddleOCR提供的模型库[PP-OCR](../../ppocr/model_list.md)和[PP-Structure](../models_list.md)下载,也可以替换成自己训练转换好的模型。
|
||||
|
||||
### 2.3 安装服务模块
|
||||
|
||||
PaddleOCR提供5种服务模块,根据需要安装所需模块。
|
||||
|
||||
在Linux环境(Windows环境请将`/`替换为`\`)下,安装模块命令如下表:
|
||||
|
||||
| 服务模块 | 命令 |
|
||||
| ------------------ | ------------------------------------------------ |
|
||||
| 检测 | `hub install deploy/hubserving/ocr_det` |
|
||||
| 分类 | `hub install deploy/hubserving/ocr_cls` |
|
||||
| 识别 | `hub install deploy/hubserving/ocr_rec` |
|
||||
| 检测+识别串联 | `hub install deploy/hubserving/ocr_system` |
|
||||
| 表格识别 | `hub install deploy/hubserving/structure_table` |
|
||||
| PP-Structure | `hub install deploy/hubserving/structure_system` |
|
||||
| 版面分析 | `hub install deploy/hubserving/structure_layout` |
|
||||
| 关键信息抽取SER | `hub install deploy/hubserving/kie_ser` |
|
||||
| 关键信息抽取SER+RE | `hub install deploy/hubserving/kie_ser_re` |
|
||||
|
||||
### 2.4 启动服务
|
||||
|
||||
#### 2.4.1. 命令行命令启动(仅支持CPU)
|
||||
|
||||
**启动命令:**
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving start --modules Module1==Version1, Module2==Version2, ... \
|
||||
--port 8866 \
|
||||
--use_multiprocess \
|
||||
--workers \
|
||||
```
|
||||
|
||||
**参数:**
|
||||
|
||||
| 参数 | 用途 |
|
||||
| ----- | ---- |
|
||||
| `--modules`/`-m` | PaddleHub Serving预安装模型,以多个Module==Version键值对的形式列出<br>**当不指定Version时,默认选择最新版本** |
|
||||
| `--port`/`-p` | 服务端口,默认为8866 |
|
||||
| `--use_multiprocess` | 是否启用并发方式,默认为单进程方式,推荐多核CPU机器使用此方式<br>**Windows操作系统只支持单进程方式** |
|
||||
| `--workers` | 在并发方式下指定的并发任务数,默认为`2*cpu_count-1`,其中`cpu_count`为CPU核数 |
|
||||
|
||||
如启动串联服务:
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving start -m ocr_system
|
||||
```
|
||||
|
||||
这样就完成了一个服务化API的部署,使用默认端口号8866。
|
||||
|
||||
#### 2.4.2 配置文件启动(支持CPU、GPU)
|
||||
|
||||
**启动命令:**
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving start -c config.json
|
||||
```
|
||||
|
||||
其中,`config.json`格式如下:
|
||||
|
||||
```json
|
||||
{
|
||||
"modules_info": {
|
||||
"ocr_system": {
|
||||
"init_args": {
|
||||
"version": "1.0.0",
|
||||
"use_gpu": true
|
||||
},
|
||||
"predict_args": {
|
||||
}
|
||||
}
|
||||
},
|
||||
"port": 8868,
|
||||
"use_multiprocess": false,
|
||||
"workers": 2
|
||||
}
|
||||
```
|
||||
|
||||
- `init_args`中的可配参数与`module.py`中的`_initialize`函数接口一致。
|
||||
|
||||
**当`use_gpu`为`true`时,表示使用GPU启动服务。**
|
||||
- `predict_args`中的可配参数与`module.py`中的`predict`函数接口一致。
|
||||
|
||||
**注意:**
|
||||
|
||||
- 使用配置文件启动服务时,其他参数会被忽略。
|
||||
- 如果使用GPU预测(即,`use_gpu`置为`true`),则需要在启动服务之前,设置CUDA_VISIBLE_DEVICES环境变量,如:
|
||||
|
||||
```bash linenums="1"
|
||||
export CUDA_VISIBLE_DEVICES=0
|
||||
```
|
||||
|
||||
- **`use_gpu`不可与`use_multiprocess`同时为`true`**。
|
||||
|
||||
如,使用GPU 3号卡启动串联服务:
|
||||
|
||||
```bash linenums="1"
|
||||
export CUDA_VISIBLE_DEVICES=3
|
||||
hub serving start -c deploy/hubserving/ocr_system/config.json
|
||||
```
|
||||
|
||||
## 3. 发送预测请求
|
||||
|
||||
配置好服务端,可使用以下命令发送预测请求,获取预测结果:
|
||||
|
||||
```bash linenums="1"
|
||||
python tools/test_hubserving.py --server_url=server_url --image_dir=image_path
|
||||
```
|
||||
|
||||
需要给脚本传递2个参数:
|
||||
|
||||
- `server_url`:服务地址,格式为`http://[ip_address]:[port]/predict/[module_name]`
|
||||
|
||||
例如,如果使用配置文件启动分类,检测、识别,检测+分类+识别3阶段,表格识别和PP-Structure服务
|
||||
|
||||
并为每个服务修改了port,那么发送请求的url将分别是:
|
||||
|
||||
```text linenums="1"
|
||||
http://127.0.0.1:8865/predict/ocr_det
|
||||
http://127.0.0.1:8866/predict/ocr_cls
|
||||
http://127.0.0.1:8867/predict/ocr_rec
|
||||
http://127.0.0.1:8868/predict/ocr_system
|
||||
http://127.0.0.1:8869/predict/structure_table
|
||||
http://127.0.0.1:8870/predict/structure_system
|
||||
http://127.0.0.1:8870/predict/structure_layout
|
||||
http://127.0.0.1:8871/predict/kie_ser
|
||||
http://127.0.0.1:8872/predict/kie_ser_re
|
||||
```
|
||||
|
||||
- `image_dir`:测试图像路径,可以是单张图片路径,也可以是图像集合目录路径
|
||||
- `visualize`:是否可视化结果,默认为False
|
||||
- `output`:可视化结果保存路径,默认为`./hubserving_result`
|
||||
|
||||
访问示例:
|
||||
|
||||
```bash linenums="1"
|
||||
python tools/test_hubserving.py --server_url=http://127.0.0.1:8868/predict/ocr_system --image_dir=./doc/imgs/ --visualize=false
|
||||
```
|
||||
|
||||
## 4. 返回结果格式说明
|
||||
|
||||
返回结果为列表(list),列表中的每一项为词典(dict),词典一共可能包含3种字段,信息如下:
|
||||
|
||||
| 字段名称 | 数据类型 | 意义 |
|
||||
| ----------- | -------- | ----- |
|
||||
| angle | str | 文本角度 |
|
||||
| text | str | 文本内容 |
|
||||
| confidence | float | 文本识别置信度或文本角度分类置信度 |
|
||||
| text_region | list | 文本位置坐标 |
|
||||
| html | str | 表格的html字符串 |
|
||||
| regions | list | 版面分析+表格识别+OCR的结果,每一项为一个list<br>包含表示区域坐标的`bbox`,区域类型的`type`和区域结果的`res`三个字段 |
|
||||
| layout | list | 版面分析的结果,每一项一个dict,包含版面区域坐标的`bbox`,区域类型的`label` |
|
||||
|
||||
不同模块返回的字段不同,如,文本识别服务模块返回结果不含`text_region`字段,具体信息如下:
|
||||
|
||||
| 字段名/模块名 | ocr_det | ocr_cls | ocr_rec | ocr_system | structure_table | structure_system | structure_layout | kie_ser | kie_re |
|
||||
| ------------- | ------- | ------- | ------- | ---------- | --------------- | ---------------- | ---------------- | ------- | ------ |
|
||||
| angle | | ✔ | | ✔ | | | |
|
||||
| text | | | ✔ | ✔ | | ✔ | | ✔ | ✔ |
|
||||
| confidence | | ✔ | ✔ | ✔ | | ✔ | | ✔ | ✔ |
|
||||
| text_region | ✔ | | | ✔ | | ✔ | | ✔ | ✔ |
|
||||
| html | | | | | ✔ | ✔ | | | |
|
||||
| regions | | | | | ✔ | ✔ | | | |
|
||||
| layout | | | | | | | ✔ | | |
|
||||
| ser_res | | | | | | | | ✔ | |
|
||||
| re_res | | | | | | | | | ✔ |
|
||||
|
||||
**说明:** 如果需要增加、删除、修改返回字段,可在相应模块的`module.py`文件中进行修改,完整流程参考下一节自定义修改服务模块。
|
||||
|
||||
## 5. 自定义修改服务模块
|
||||
|
||||
如果需要修改服务逻辑,一般需要操作以下步骤(以修改`deploy/hubserving/ocr_system`为例):
|
||||
|
||||
1. 停止服务:
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving stop --port/-p XXXX
|
||||
```
|
||||
|
||||
2. 到`deploy/hubserving/ocr_system`下的`module.py`和`params.py`等文件中根据实际需求修改代码。
|
||||
|
||||
例如,如果需要替换部署服务所用模型,则需要到`params.py`中修改模型路径参数`det_model_dir`和`rec_model_dir`,如果需要关闭文本方向分类器,则将参数`use_angle_cls`置为`False`
|
||||
|
||||
当然,同时可能还需要修改其他相关参数,请根据实际情况修改调试。
|
||||
|
||||
**强烈建议修改后先直接运行`module.py`调试,能正确运行预测后再启动服务测试。**
|
||||
|
||||
**注意:** PPOCR-v3识别模型使用的图片输入shape为`3,48,320`,因此需要修改`params.py`中的`cfg.rec_image_shape = "3, 48, 320"`,如果不使用PPOCR-v3识别模型,则无需修改该参数。
|
||||
3. (可选)如果想要重命名模块需要更改`module.py`文件中的以下行:
|
||||
- [`from deploy.hubserving.ocr_system.params import read_params`中的`ocr_system`](https://github.com/PaddlePaddle/PaddleOCR/blob/a923f35de57b5e378f8dd16e54d0a3e4f51267fd/deploy/hubserving/ocr_system/module.py#L35)
|
||||
- [`name="ocr_system",`中的`ocr_system`](https://github.com/PaddlePaddle/PaddleOCR/blob/a923f35de57b5e378f8dd16e54d0a3e4f51267fd/deploy/hubserving/ocr_system/module.py#L39)
|
||||
4. (可选)可能需要删除`__pycache__`目录以强制刷新CPython缓存:
|
||||
|
||||
```bash linenums="1"
|
||||
find deploy/hubserving/ocr_system -name '__pycache__' -exec rm -r {} \;
|
||||
```
|
||||
|
||||
5. 安装修改后的新服务包:
|
||||
|
||||
```bash linenums="1"
|
||||
hub install deploy/hubserving/ocr_system
|
||||
```
|
||||
|
||||
6. 重新启动服务:
|
||||
|
||||
```bash linenums="1"
|
||||
hub serving start -m ocr_system
|
||||
```
|
||||
116
docs/version2.x/ppstructure/infer_deploy/python_infer.en.md
Normal file
116
docs/version2.x/ppstructure/infer_deploy/python_infer.en.md
Normal file
@@ -0,0 +1,116 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# Python Inference
|
||||
|
||||
## 1. Layout Structured Analysis
|
||||
|
||||
Go to the `ppstructure` directory
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
|
||||
# download model
|
||||
mkdir inference && cd inference
|
||||
# Download the PP-StructureV2 layout analysis model and unzip it
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_layout_infer.tar && tar xf picodet_lcnet_x1_0_layout_infer.tar
|
||||
# Download the PP-OCRv3 text detection model and unzip it
|
||||
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv3_mobile_det_infer.tar && tar xf PP-OCRv3_mobile_det_infer.tar
|
||||
# Download the PP-OCRv3 text recognition model and unzip it
|
||||
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv3_mobile_rec_infer.tar && tar xf PP-OCRv3_mobile_rec_infer.tar
|
||||
# Download the PP-StructureV2 form recognition model and unzip it
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/paddle3.0b2/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar
|
||||
cd ..
|
||||
```
|
||||
|
||||
### 1.1 layout analysis + table recognition
|
||||
|
||||
```bash linenums="1"
|
||||
python3 predict_system.py --det_model_dir=inference/PP-OCRv3_mobile_det_infer \
|
||||
--rec_model_dir=inference/PP-OCRv3_mobile_rec_infer \
|
||||
--table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_infer \
|
||||
--layout_model_dir=inference/picodet_lcnet_x1_0_layout_infer \
|
||||
--image_dir=./docs/table/1.png \
|
||||
--rec_char_dict_path=../ppocr/utils/ppocr_keys_v1.txt \
|
||||
--table_char_dict_path=../ppocr/utils/dict/table_structure_dict_ch.txt \
|
||||
--output=../output \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf
|
||||
```
|
||||
|
||||
After the operation is completed, each image will have a directory with the same name in the `structure` directory under the directory specified by the `output` field. Each table in the image will be stored as an excel, and the picture area will be cropped and saved. The filename of excel and picture is their coordinates in the image. Detailed results are stored in the `res.txt` file.
|
||||
|
||||
### 1.2 layout analysis
|
||||
|
||||
```bash linenums="1"
|
||||
python3 predict_system.py --layout_model_dir=inference/picodet_lcnet_x1_0_layout_infer \
|
||||
--image_dir=./docs/table/1.png \
|
||||
--output=../output \
|
||||
--table=false \
|
||||
--ocr=false
|
||||
```
|
||||
|
||||
After the operation is completed, each image will have a directory with the same name in the `structure` directory under the directory specified by the `output` field. Each picture in image will be cropped and saved. The filename of picture area is their coordinates in the image. Layout analysis results will be stored in the `res.txt` file
|
||||
|
||||
### 1.3 table recognition
|
||||
|
||||
```bash linenums="1"
|
||||
python3 predict_system.py --det_model_dir=inference/PP-OCRv3_mobile_det_infer \
|
||||
--rec_model_dir=inference/PP-OCRv3_mobile_rec_infer \
|
||||
--table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_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_ch.txt \
|
||||
--output=../output \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf \
|
||||
--layout=false
|
||||
```
|
||||
|
||||
After the operation is completed, each image will have a directory with the same name in the `structure` directory under the directory specified by the `output` field. Each table in the image will be stored as an excel. The filename of excel is their coordinates in the image.
|
||||
|
||||
## 2. Key Information Extraction
|
||||
|
||||
### 2.1 SER
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
|
||||
mkdir inference && cd inference
|
||||
# download model
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_infer.tar && tar -xf ser_vi_layoutxlm_xfund_infer.tar
|
||||
cd ..
|
||||
python3 predict_system.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" \
|
||||
--mode=kie
|
||||
```
|
||||
|
||||
After the operation is completed, each image will store the visualized image in the `kie` directory under the directory specified by the `output` field, and the image name is the same as the input image name.
|
||||
|
||||
### 2.2 RE+SER
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
|
||||
mkdir inference && cd inference
|
||||
# download model
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/ser_vi_layoutxlm_xfund_infer.tar && tar -xf ser_vi_layoutxlm_xfund_infer.tar
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_infer.tar && tar -xf re_vi_layoutxlm_xfund_infer.tar
|
||||
cd ..
|
||||
|
||||
python3 predict_system.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--re_model_dir=./inference/re_vi_layoutxlm_xfund_infer \
|
||||
--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" \
|
||||
--mode=kie
|
||||
```
|
||||
|
||||
After the operation is completed, each image will have a directory with the same name in the `kie` directory under the directory specified by the `output` field, where the visual images and prediction results are stored.
|
||||
119
docs/version2.x/ppstructure/infer_deploy/python_infer.md
Normal file
119
docs/version2.x/ppstructure/infer_deploy/python_infer.md
Normal file
@@ -0,0 +1,119 @@
|
||||
---
|
||||
comments: true
|
||||
---
|
||||
|
||||
# 基于Python预测引擎推理
|
||||
|
||||
## 1. 版面信息抽取
|
||||
|
||||
进入`ppstructure`目录
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
```
|
||||
|
||||
下载模型
|
||||
|
||||
```bash linenums="1"
|
||||
mkdir inference && cd inference
|
||||
# 下载PP-StructureV2版面分析模型并解压
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_layout_infer.tar && tar xf picodet_lcnet_x1_0_layout_infer.tar
|
||||
# 下载PP-OCRv3文本检测模型并解压
|
||||
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv3_mobile_det_infer.tar && tar xf PP-OCRv3_mobile_det_infer.tar
|
||||
# 下载PP-OCRv3文本识别模型并解压
|
||||
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv3_mobile_rec_infer.tar && tar xf PP-OCRv3_mobile_rec_infer.tar
|
||||
# 下载PP-StructureV2表格识别模型并解压
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/paddle3.0b2/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar
|
||||
cd ..
|
||||
```
|
||||
|
||||
### 1.1 版面分析+表格识别
|
||||
|
||||
```bash linenums="1"
|
||||
python3 predict_system.py --det_model_dir=inference/PP-OCRv3_mobile_det_infer \
|
||||
--rec_model_dir=inference/PP-OCRv3_mobile_rec_infer \
|
||||
--table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_infer \
|
||||
--layout_model_dir=inference/picodet_lcnet_x1_0_layout_infer \
|
||||
--image_dir=./docs/table/1.png \
|
||||
--rec_char_dict_path=../ppocr/utils/ppocr_keys_v1.txt \
|
||||
--table_char_dict_path=../ppocr/utils/dict/table_structure_dict_ch.txt \
|
||||
--output=../output \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf
|
||||
```
|
||||
|
||||
运行完成后,每张图片会在`output`字段指定的目录下的`structure`目录下有一个同名目录,图片里的每个表格会存储为一个excel,图片区域会被裁剪之后保存下来,excel文件和图片名为表格在图片里的坐标。详细的结果会存储在`res.txt`文件中。
|
||||
|
||||
### 1.2 版面分析
|
||||
|
||||
```bash linenums="1"
|
||||
python3 predict_system.py --layout_model_dir=inference/picodet_lcnet_x1_0_layout_infer \
|
||||
--image_dir=./docs/table/1.png \
|
||||
--output=../output \
|
||||
--table=false \
|
||||
--ocr=false
|
||||
```
|
||||
|
||||
运行完成后,每张图片会在`output`字段指定的目录下的`structure`目录下有一个同名目录,图片区域会被裁剪之后保存下来,图片名为表格在图片里的坐标。版面分析结果会存储在`res.txt`文件中。
|
||||
|
||||
### 1.3 表格识别
|
||||
|
||||
```bash linenums="1"
|
||||
python3 predict_system.py --det_model_dir=inference/PP-OCRv3_mobile_det_infer \
|
||||
--rec_model_dir=inference/PP-OCRv3_mobile_rec_infer \
|
||||
--table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_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_ch.txt \
|
||||
--output=../output \
|
||||
--vis_font_path=../doc/fonts/simfang.ttf \
|
||||
--layout=false
|
||||
```
|
||||
|
||||
运行完成后,每张图片会在`output`字段指定的目录下的`structure`目录下有一个同名目录,表格会存储为一个excel,excel文件名为`[0,0,img_h,img_w]`。
|
||||
|
||||
## 2. 关键信息抽取
|
||||
|
||||
### 2.1 SER
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
|
||||
mkdir inference && cd inference
|
||||
# 下载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
|
||||
cd ..
|
||||
python3 predict_system.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" \
|
||||
--mode=kie
|
||||
```
|
||||
|
||||
运行完成后,每张图片会在`output`字段指定的目录下的`kie`目录下存放可视化之后的图片,图片名和输入图片名一致。
|
||||
|
||||
### 2.2 RE+SER
|
||||
|
||||
```bash linenums="1"
|
||||
cd ppstructure
|
||||
|
||||
mkdir inference && cd inference
|
||||
# 下载RE 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
|
||||
wget https://paddleocr.bj.bcebos.com/ppstructure/models/vi_layoutxlm/re_vi_layoutxlm_xfund_infer.tar && tar -xf re_vi_layoutxlm_xfund_infer.tar
|
||||
cd ..
|
||||
|
||||
python3 predict_system.py \
|
||||
--kie_algorithm=LayoutXLM \
|
||||
--re_model_dir=./inference/re_vi_layoutxlm_xfund_infer \
|
||||
--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" \
|
||||
--mode=kie
|
||||
```
|
||||
|
||||
运行完成后,每张图片会在`output`字段指定的目录下的`kie`目录下有一个同名目录,目录中存放可视化图片和预测结果。
|
||||
Reference in New Issue
Block a user