Skip to content

Add ppocr series models #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/det/ppocr/ch_PP-OCRv2_det_cml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: DistillationDBPostProcess
binary_thresh: 0.3
box_thresh: 0.6
max_candidates: 1000
expand_ratio: 1.5


eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
- ScalePadImage:
- NormalizeImage:
mean: [ 123.675, 116.28 , 103.53 ]
std: [ 58.395, 57.12 , 57.375 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/det/ppocr/ch_det_mv3_db_v2.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: DBPostprocess
binary_thresh: 0.3
box_thresh: 0.6
max_candidates: 1000
expand_ratio: 1.5


eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
- ScalePadImage:
- NormalizeImage:
mean: [ 123.675, 116.28 , 103.53 ]
std: [ 58.395, 57.12 , 57.375 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/arabic_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
postprocess:
name: DistillationCTCLabelDecode
use_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: True
- ToCHWImage:
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/cyrillic_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/devanagari_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/en_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/japan_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/ka_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/korean_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/latin_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- CTCLabelEncode:
- RecResizeImg:
padding: True
- ToCHWImage:
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: True
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/ta_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
20 changes: 20 additions & 0 deletions deploy/py_infer/src/configs/rec/ppocr/te_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
postprocess:
name: CTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False

eval:
dataset:
transform_pipeline:
- DecodeImage:
img_mode: BGR
channel_first: False
to_float32: True
- RecResizeImg:
padding: False
- NormalizeImage:
mean: [ 127.5, 127.5, 127.5 ]
std: [ 127.5, 127.5, 127.5 ]
is_hwc: True
- ToCHWImage:
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
POSTPROCESS_MAPPING_OPS = {
"DBPostprocess": db_postprocess.DBPostprocess,
"RecCTCLabelDecode": rec_postprocess.RecCTCLabelDecode,
"ClsPostprocess": cls_postprocess.ClsPostprocess
"ClsPostprocess": cls_postprocess.ClsPostprocess,
"DistillationDBPostProcess": db_postprocess.DBPostprocess,
"DistillationCTCLabelDecode": rec_postprocess.RecCTCLabelDecode,
"CTCLabelDecode": rec_postprocess.RecCTCLabelDecode
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RecCTCLabelDecode(object):
def __init__(self,
character_dict_path=None,
use_space_char=False,
use_redundant_space_char=False,
blank_at_last=True,
lower=False,
):
Expand Down Expand Up @@ -48,6 +49,9 @@ def __init__(self,
"WARNING: The dict still contains space char in dict although use_space_char is set to be False, because the space char is coded in the dictionary file ",
character_dict_path)

if use_redundant_space_char:
char_list.append(' ') # paddleOCR rec models need two space char

self.num_valid_chars = len(char_list) # the number of valid chars (including space char if used)

# add blank token for padding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ..preprocess import transforms

PREPROCESS_SKIP_OPS = ["DetLabelEncode", "RecCTCLabelEncode"]
PREPROCESS_SKIP_OPS = ["DetLabelEncode", "RecCTCLabelEncode", "CTCLabelEncode"]

PREPROCESS_MAPPING_OPS = {
"DecodeImage": transforms.DecodeImage,
Expand Down
31 changes: 26 additions & 5 deletions deploy/py_infer/src/utils/adapted/paddleocr_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@


PADDLEOCR_MODELS = {
"ch_pp_server_det_v2.0": "det/ppocr/ch_det_res18_db_v2.0.yaml", # ch_ppocr_server_v2.0_det
"ch_pp_det_v3": "det/ppocr/ch_PP-OCRv3_det_cml.yaml", # ch_PP-OCRv3_det
"ch_pp_server_rec_v2.0": "rec/ppocr/rec_chinese_common_train_v2.0.yaml", # ch_ppocr_server_v2.0_rec
"ch_pp_rec_v3": "rec/ppocr/ch_PP-OCRv3_rec_distillation.yaml", # ch_PP-OCRv3_rec
"ch_pp_mobile_cls_v2.0": "cls/ppocr/cls_mv3.yaml" # ch_ppocr_mobile_v2.0_cls
"ch_pp_server_det_v2.0": "det/ppocr/ch_det_res18_db_v2.0.yaml", # ch_ppocr_server_v2.0_det
"ch_pp_det_OCRv3": "det/ppocr/ch_PP-OCRv3_det_cml.yaml", # ch_PP-OCRv3_det
"ch_pp_server_rec_v2.0": "rec/ppocr/rec_chinese_common_train_v2.0.yaml", # ch_ppocr_server_v2.0_rec
"ch_pp_rec_OCRv3": "rec/ppocr/ch_PP-OCRv3_rec_distillation.yaml", # ch_PP-OCRv3_rec
"ch_pp_mobile_cls_v2.0": "cls/ppocr/cls_mv3.yaml", # ch_ppocr_mobile_v2.0_cls
"ch_pp_det_OCRv2": "det/ppocr/ch_PP-OCRv2_det_cml.yaml", # ch_PP-OCRv2_det
"ch_pp_mobile_det_v2.0_slim": "det/ppocr/ch_det_mv3_db_v2.0.yaml", # ch_ppocr_mobile_slim_v2.0_det
"ch_pp_mobile_det_v2.0": "det/ppocr/ch_det_mv3_db_v2.0.yaml", # ch_ppocr_mobile_v2.0_det
"en_pp_det_OCRv3": "det/ppocr/ch_PP-OCRv3_det_cml.yaml", # en_PP-OCRv3_det
"ml_pp_det_OCRv3": "det/ppocr/ch_PP-OCRv3_det_cml.yaml", # ml_PP-OCRv3_det
"ch_pp_rec_OCRv2": "rec/ppocr/ch_PP-OCRv2_rec_distillation.yaml", # ch_PP-OCRv2_rec
"ch_pp_mobile_rec_v2.0": "rec/ppocr/rec_chinese_lite_train_v2.0.yaml", # ch_ppocr_mobile_v2.0_rec
"en_pp_rec_OCRv3": "rec/ppocr/en_PP-OCRv3_rec.yaml", # en_PP-OCRv3_rec
"en_pp_mobile_rec_number_v2.0_slim": "rec/ppocr/rec_en_number_lite_train.yaml", # en_number_mobile_slim_v2.0_rec
"en_pp_mobile_rec_number_v2.0": "rec/ppocr/rec_en_number_lite_train.yaml", # en_number_mobile_v2.0_rec
"korean_pp_rec_OCRv3": "rec/ppocr/korean_PP-OCRv3_rec.yaml", # korean_PP-OCRv3_rec
"japan_pp_rec_OCRv3": "rec/ppocr/japan_PP-OCRv3_rec.yaml", # japan_PP-OCRv3_rec
"chinese_cht_pp_rec_OCRv3": "rec/ppocr/chinese_cht_PP-OCRv3_rec.yaml", # chinese_cht_PP-OCRv3_rec
"te_pp_rec_OCRv3": "rec/ppocr/te_PP-OCRv3_rec.yaml", # te_PP-OCRv3_rec
"ka_pp_rec_OCRv3": "rec/ppocr/ka_PP-OCRv3_rec.yaml", # ka_PP-OCRv3_rec
"ta_pp_rec_OCRv3": "rec/ppocr/ta_PP-OCRv3_rec.yaml", # ta_PP-OCRv3_rec
"latin_pp_rec_OCRv3": "rec/ppocr/latin_PP-OCRv3_rec.yaml", # latin_PP-OCRv3_rec
"arabic_pp_rec_OCRv3": "rec/ppocr/arabic_PP-OCRv3_rec.yaml", # arabic_PP-OCRv3_rec
"cyrillic_pp_rec_OCRv3": "rec/ppocr/cyrillic_PP-OCRv3_rec.yaml", # cyrillic_PP-OCRv3_rec
"devanagari_pp_rec_OCRv3": "rec/ppocr/devanagari_PP-OCRv3_rec.yaml" # devanagari_PP-OCRv3_rec

}