Skip to content

πŸ“„ Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

Fix the bug of the python v3 rec

SWHL46e8da6cb041
diff --git a/python/onnxruntime_infer/ch_ppocr_mobile_v2_rec/text_recognize.py b/python/onnxruntime_infer/ch_ppocr_mobile_v2_rec/text_recognize.py
index d196148..ea0c967 100644
--- a/python/onnxruntime_infer/ch_ppocr_mobile_v2_rec/text_recognize.py
+++ b/python/onnxruntime_infer/ch_ppocr_mobile_v2_rec/text_recognize.py
@@ -34,10 +34,11 @@ class TextRecognizer(object):
self.rec_image_shape = [3, 32, 320]
self.rec_batch_num = 6
- if keys_path is not None:
- self.character_dict_path = keys_path
- else:
+ if keys_path is None:
self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
+ else:
+ self.character_dict_path = keys_path
+
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
sess_opt = onnxruntime.SessionOptions()
diff --git a/python/onnxruntime_infer/ch_ppocr_mobile_v3_rec/text_recognize.py b/python/onnxruntime_infer/ch_ppocr_mobile_v3_rec/text_recognize.py
index cdf8f0a..b548d0f 100644
--- a/python/onnxruntime_infer/ch_ppocr_mobile_v3_rec/text_recognize.py
+++ b/python/onnxruntime_infer/ch_ppocr_mobile_v3_rec/text_recognize.py
@@ -30,12 +30,16 @@ root_path = Path(__file__).parent
class TextRecognizer(object):
- def __init__(self, rec_model_path):
+ def __init__(self, rec_model_path, keys_path=None):
self.rec_image_shape = [3, 48, 320]
self.character_type = 'ch'
self.rec_batch_num = 6
- self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
+ if keys_path is None:
+ self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
+ else:
+ self.character_dict_path = keys_path
+
self.use_space_char = True
self.postprocess_op = CTCLabelDecode(self.character_dict_path,
self.character_type,
diff --git a/python/onnxruntime_infer/ch_ppocr_server_v2_rec/text_recognize.py b/python/onnxruntime_infer/ch_ppocr_server_v2_rec/text_recognize.py
index 9817882..eeba39f 100644
--- a/python/onnxruntime_infer/ch_ppocr_server_v2_rec/text_recognize.py
+++ b/python/onnxruntime_infer/ch_ppocr_server_v2_rec/text_recognize.py
@@ -34,10 +34,11 @@ class TextRecognizer(object):
self.rec_image_shape = [3, 32, 320]
self.rec_batch_num = 6
- if keys_path is not None:
- self.character_dict_path = keys_path
- else:
+ if keys_path is None:
self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
+ else:
+ self.character_dict_path = keys_path
+
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
sess_opt = onnxruntime.SessionOptions()
diff --git a/python/onnxruntime_infer/rapid_ocr_api.py b/python/onnxruntime_infer/rapid_ocr_api.py
index 7bd3a14..4bf8703 100644
--- a/python/onnxruntime_infer/rapid_ocr_api.py
+++ b/python/onnxruntime_infer/rapid_ocr_api.py
@@ -290,7 +290,10 @@ if __name__ == '__main__':
if args.rec_model_path.find('server') != -1:
from ch_ppocr_server_v2_rec import TextRecognizer
else:
- from ch_ppocr_mobile_v2_rec import TextRecognizer
+ if args.rec_model_path.find('v2') != -1:
+ from ch_ppocr_mobile_v2_rec import TextRecognizer
+ elif args.rec_model_path.find('v3') != -1:
+ from ch_ppocr_mobile_v3_rec import TextRecognizer
text_sys = TextSystem(args.det_model_path,
args.rec_model_path,