Skip to content

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

add release memory parameter

SWHL9590499f3b70
diff --git a/ocrweb/resources/ch_ppocr_mobile_v2_cls/text_cls.py b/ocrweb/resources/ch_ppocr_mobile_v2_cls/text_cls.py
index b226403..e6974ca 100644
--- a/ocrweb/resources/ch_ppocr_mobile_v2_cls/text_cls.py
+++ b/ocrweb/resources/ch_ppocr_mobile_v2_cls/text_cls.py
@@ -18,12 +18,12 @@ import time
import cv2
import numpy as np
-import onnxruntime as ort
+import onnxruntime
try:
- from .utils import check_and_read_gif, get_image_file_list, ClsPostProcess
+ from .utils import ClsPostProcess, check_and_read_gif, get_image_file_list
except:
- from utils import check_and_read_gif, get_image_file_list, ClsPostProcess
+ from utils import ClsPostProcess, check_and_read_gif, get_image_file_list
class TextClassifier(object):
@@ -32,7 +32,11 @@ class TextClassifier(object):
self.cls_batch_num = 6
self.cls_thresh = 0.9
self.postprocess_op = ClsPostProcess(label_list=['0', '180'])
- self.session = ort.InferenceSession(cls_model_path)
+
+ sess_opt = onnxruntime.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = onnxruntime.InferenceSession(cls_model_path, sess_opt)
def resize_norm_img(self, img):
imgC, imgH, imgW = self.cls_image_shape
diff --git a/ocrweb/resources/ch_ppocr_mobile_v2_det/text_detect.py b/ocrweb/resources/ch_ppocr_mobile_v2_det/text_detect.py
index 78abb82..32673be 100644
--- a/ocrweb/resources/ch_ppocr_mobile_v2_det/text_detect.py
+++ b/ocrweb/resources/ch_ppocr_mobile_v2_det/text_detect.py
@@ -56,7 +56,10 @@ class TextDetector(object):
max_candidates=1000,
unclip_ratio=2.0,
use_dilation=True)
- self.session = onnxruntime.InferenceSession(det_model_path)
+ sess_opt = onnxruntime.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = onnxruntime.InferenceSession(det_model_path, sess_opt)
self.input_name = self.session.get_inputs()[0].name
self.output_name = self.session.get_outputs()[0].name
diff --git a/ocrweb/resources/ch_ppocr_mobile_v2_rec/text_recognize.py b/ocrweb/resources/ch_ppocr_mobile_v2_rec/text_recognize.py
index 42a63db..54aece6 100644
--- a/ocrweb/resources/ch_ppocr_mobile_v2_rec/text_recognize.py
+++ b/ocrweb/resources/ch_ppocr_mobile_v2_rec/text_recognize.py
@@ -41,7 +41,11 @@ class TextRecognizer(object):
self.postprocess_op = CTCLabelDecode(self.character_dict_path,
self.character_type,
self.use_space_char)
- self.session = onnxruntime.InferenceSession(rec_model_path)
+
+ sess_opt = onnxruntime.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = onnxruntime.InferenceSession(rec_model_path, sess_opt)
def resize_norm_img(self, img, max_wh_ratio):
img_channel, img_height, img_width = self.rec_image_shape
diff --git a/python/ch_ppocr_mobile_v2_cls/text_cls.py b/python/ch_ppocr_mobile_v2_cls/text_cls.py
index 8992ec4..e66b84f 100755
--- a/python/ch_ppocr_mobile_v2_cls/text_cls.py
+++ b/python/ch_ppocr_mobile_v2_cls/text_cls.py
@@ -21,9 +21,9 @@ import numpy as np
import onnxruntime as ort
try:
- from .utils import check_and_read_gif, get_image_file_list, ClsPostProcess
+ from .utils import ClsPostProcess, check_and_read_gif, get_image_file_list
except:
- from utils import check_and_read_gif, get_image_file_list, ClsPostProcess
+ from utils import ClsPostProcess, check_and_read_gif, get_image_file_list
class TextClassifier(object):
@@ -32,7 +32,11 @@ class TextClassifier(object):
self.cls_batch_num = 6
self.cls_thresh = 0.9
self.postprocess_op = ClsPostProcess(label_list=['0', '180'])
- self.session = ort.InferenceSession(cls_model_path)
+
+ sess_opt = ort.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = ort.InferenceSession(cls_model_path, sess_opt)
def resize_norm_img(self, img):
imgC, imgH, imgW = self.cls_image_shape
diff --git a/python/ch_ppocr_mobile_v2_det/text_detect.py b/python/ch_ppocr_mobile_v2_det/text_detect.py
index e02fbff..87bb51a 100755
--- a/python/ch_ppocr_mobile_v2_det/text_detect.py
+++ b/python/ch_ppocr_mobile_v2_det/text_detect.py
@@ -56,7 +56,10 @@ class TextDetector(object):
max_candidates=1000,
unclip_ratio=1.6,
use_dilation=True)
- self.session = onnxruntime.InferenceSession(det_model_path)
+ sess_opt = onnxruntime.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = onnxruntime.InferenceSession(det_model_path, sess_opt)
self.input_name = self.session.get_inputs()[0].name
self.output_name = self.session.get_outputs()[0].name
diff --git a/python/ch_ppocr_mobile_v2_rec/text_recognize.py b/python/ch_ppocr_mobile_v2_rec/text_recognize.py
index 53ec726..baeee61 100755
--- a/python/ch_ppocr_mobile_v2_rec/text_recognize.py
+++ b/python/ch_ppocr_mobile_v2_rec/text_recognize.py
@@ -36,7 +36,11 @@ class TextRecognizer(object):
self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
- self.session = onnxruntime.InferenceSession(rec_model_path)
+
+ sess_opt = onnxruntime.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = onnxruntime.InferenceSession(rec_model_path, sess_opt)
def resize_norm_img(self, img, max_wh_ratio):
img_channel, img_height, img_width = self.rec_image_shape
diff --git a/python/ch_ppocr_server_v2_det/text_detect.py b/python/ch_ppocr_server_v2_det/text_detect.py
index a342a8c..d586766 100755
--- a/python/ch_ppocr_server_v2_det/text_detect.py
+++ b/python/ch_ppocr_server_v2_det/text_detect.py
@@ -54,7 +54,10 @@ class TextDetector(object):
unclip_ratio=1.6,
use_dilation=True)
- self.session = onnxruntime.InferenceSession(det_model_path)
+ sess_opt = onnxruntime.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = onnxruntime.InferenceSession(det_model_path, sess_opt)
self.input_name = self.session.get_inputs()[0].name
self.output_name = self.session.get_outputs()[0].name
diff --git a/python/ch_ppocr_server_v2_rec/text_recognize.py b/python/ch_ppocr_server_v2_rec/text_recognize.py
index 5f1e799..894330f 100755
--- a/python/ch_ppocr_server_v2_rec/text_recognize.py
+++ b/python/ch_ppocr_server_v2_rec/text_recognize.py
@@ -36,7 +36,11 @@ class TextRecognizer(object):
self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
- self.session = onnxruntime.InferenceSession(rec_model_path)
+
+ sess_opt = onnxruntime.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = onnxruntime.InferenceSession(rec_model_path, sess_opt)
def resize_norm_img(self, img, max_wh_ratio):
img_channel, img_height, img_width = self.rec_image_shape
diff --git a/python/inference_results/infer_1.jpg b/python/inference_results/infer_1.jpg
deleted file mode 100644
index 0ba0b46..0000000
Binary files a/python/inference_results/infer_1.jpg and /dev/null differ
diff --git a/python/japan_ppocr_mobile_v2_rec/text_recognize.py b/python/japan_ppocr_mobile_v2_rec/text_recognize.py
index ec398b3..e7877aa 100644
--- a/python/japan_ppocr_mobile_v2_rec/text_recognize.py
+++ b/python/japan_ppocr_mobile_v2_rec/text_recognize.py
@@ -36,7 +36,11 @@ class TextRecognizer(object):
self.character_dict_path = str(root_path / 'japan_dict.txt')
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
- self.session = onnxruntime.InferenceSession(rec_model_path)
+
+ sess_opt = onnxruntime.SessionOptions()
+ sess_opt.log_severity_level = 4
+ sess_opt.enable_cpu_mem_arena = False
+ self.session = onnxruntime.InferenceSession(rec_model_path, sess_opt)
def resize_norm_img(self, img, max_wh_ratio):
img_channel, img_height, img_width = self.rec_image_shape
diff --git a/python/rapidOCR.py b/python/rapidOCR.py
index c733b97..b9f60ee 100644
--- a/python/rapidOCR.py
+++ b/python/rapidOCR.py
@@ -16,6 +16,7 @@ drop_score = 0.5
def str2bool(v):
return v.lower() in ("true", "t", "1")
+
def check_and_read_gif(img_path):
if Path(img_path).name[-3:] in ['gif', 'GIF']:
gif = cv2.VideoCapture(img_path)