@@ -20,7 +20,7 @@ PaddleOCR provides 2 service deployment methods:
...
@@ -20,7 +20,7 @@ PaddleOCR provides 2 service deployment methods:
# Service deployment based on PaddleHub Serving
# Service deployment based on PaddleHub Serving
The hubserving service deployment directory includes six service packages: text detection, text angle class, text recognition, text detection+text angle class+text recognition three-stage series connection, table recognition and PP-Structure. Please select the corresponding service package to install and start service according to your needs. The directory is as follows:
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, table recognition, PP-Structure and layout analysis. Please select the corresponding service package to install and start service according to your needs. The directory is as follows:
```
```
deploy/hubserving/
deploy/hubserving/
└─ ocr_det text detection module service package
└─ ocr_det text detection module service package
...
@@ -29,6 +29,7 @@ deploy/hubserving/
...
@@ -29,6 +29,7 @@ deploy/hubserving/
└─ ocr_system text detection+text angle class+text recognition three-stage series connection service package
└─ ocr_system text detection+text angle class+text recognition three-stage series connection service package
└─ structure_table table recognition service package
└─ structure_table table recognition service package
└─ structure_system PP-Structure service package
└─ structure_system PP-Structure service package
└─ structure_layout layout analysis service package
```
```
Each service pack contains 3 files. Take the 2-stage series connection service package as an example, the directory is as follows:
Each service pack contains 3 files. Take the 2-stage series connection service package as an example, the directory is as follows:
...
@@ -43,6 +44,7 @@ deploy/hubserving/ocr_system/
...
@@ -43,6 +44,7 @@ deploy/hubserving/ocr_system/
* 2022.05.05 add PP-OCRv3 text detection and recognition models.
* 2022.05.05 add PP-OCRv3 text detection and recognition models.
* 2022.03.30 add PP-Structure and table recognition services。
* 2022.03.30 add PP-Structure and table recognition services。
* 2022.08.23 add layout analysis services。
## 2. Quick start service
## 2. Quick start service
...
@@ -61,7 +63,7 @@ Before installing the service module, you need to prepare the inference model an
...
@@ -61,7 +63,7 @@ Before installing the service module, you need to prepare the inference model an
text detection model: ./inference/ch_PP-OCRv3_det_infer/
text detection model: ./inference/ch_PP-OCRv3_det_infer/
text recognition model: ./inference/ch_PP-OCRv3_rec_infer/
text recognition model: ./inference/ch_PP-OCRv3_rec_infer/
text angle classifier: ./inference/ch_ppocr_mobile_v2.0_cls_infer/
text angle classifier: ./inference/ch_ppocr_mobile_v2.0_cls_infer/
@@ -190,8 +198,9 @@ For example, if using the configuration file to start the text angle classificat
...
@@ -190,8 +198,9 @@ For example, if using the configuration file to start the text angle classificat
`http://127.0.0.1:8866/predict/ocr_cls`
`http://127.0.0.1:8866/predict/ocr_cls`
`http://127.0.0.1:8867/predict/ocr_rec`
`http://127.0.0.1:8867/predict/ocr_rec`
`http://127.0.0.1:8868/predict/ocr_system`
`http://127.0.0.1:8868/predict/ocr_system`
`http://127.0.0.1:8869/predict/structure_table`
`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_system`
`http://127.0.0.1:8870/predict/structure_layout`
-**image_dir**:Test image path, can be a single image path or an image directory path
-**image_dir**:Test image path, can be a single image path or an image directory path
-**visualize**:Whether to visualize the results, the default value is False
-**visualize**:Whether to visualize the results, the default value is False
-**output**:The floder to save Visualization result, default value is `./hubserving_result`
-**output**:The floder to save Visualization result, default value is `./hubserving_result`
...
@@ -212,17 +221,19 @@ The returned result is a list. Each item in the list is a dict. The dict may con
...
@@ -212,17 +221,19 @@ The returned result is a list. Each item in the list is a dict. The dict may con
|text_region|list|text location coordinates|
|text_region|list|text location coordinates|
|html|str|table html str|
|html|str|table html str|
|regions|list|The result of layout analysis + table recognition + OCR, each item is a list, including `bbox` indicating area coordinates, `type` of area type and `res` of area results|
|regions|list|The result of layout analysis + table recognition + OCR, each item is a list, 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`. The details are as follows:
The fields returned by different modules are different. For example, the results returned by the text recognition service module do not contain `text_region`. The details are as follows:
| field name/module name | ocr_det | ocr_cls | ocr_rec | ocr_system | structure_table | structure_system |
| field name/module name | ocr_det | ocr_cls | ocr_rec | ocr_system | structure_table | structure_system | structure_layout |
| --- | --- | --- | --- | --- | --- |--- |
| --- | --- | --- | --- | --- | --- |--- |--- |
|angle| | ✔ | | ✔ | ||
|angle| | ✔ | | ✔ | || |
|text| | |✔|✔| | ✔ |
|text| | |✔|✔| | ✔ | |
|confidence| |✔ |✔| | | ✔|
|confidence| |✔ |✔| | | ✔| |
|text_region| ✔| | |✔ | | ✔|
|text_region| ✔| | |✔ | | ✔| |
|html| | | | |✔ |✔|
|html| | | | |✔ |✔| |
|regions| | | | |✔ |✔ |
|regions| | | | |✔ |✔ | |
|layout| | | | | | |✔ |
**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.
**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.
"Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id."
)
cfg.ir_optim=True
cfg.enable_mkldnn=enable_mkldnn
self.layout_predictor=_LayoutPredictor(cfg)
defmerge_configs(self):
# deafult cfg
backup_argv=copy.deepcopy(sys.argv)
sys.argv=sys.argv[:1]
cfg=parse_args()
update_cfg_map=vars(read_params())
forkeyinupdate_cfg_map:
cfg.__setattr__(key,update_cfg_map[key])
sys.argv=copy.deepcopy(backup_argv)
returncfg
defread_images(self,paths=[]):
images=[]
forimg_pathinpaths:
assertos.path.isfile(
img_path),"The {} isn't a valid file.".format(img_path)
img=cv2.imread(img_path)
ifimgisNone:
logger.info("error in loading image:{}".format(img_path))
continue
images.append(img)
returnimages
defpredict(self,images=[],paths=[]):
"""
Get the chinese texts in the predicted images.
Args:
images (list(numpy.ndarray)): images data, shape of each is [H, W, C]. If images not paths
paths (list[str]): The paths of images. If paths not images