📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
[Fix] the inference of cls by the openvino.
SWHLde746984e1a4
diff --git a/README.md b/README.mdindex 5c18de8..089f19f 100755--- a/README.md+++ b/README.md@@ -25,9 +25,9 @@- [RapidOCR (捷智OCR)](#rapidocr-捷智ocr)- [简介](#简介)- [近期更新(more)](#近期更新more)+ - [🛴2022-09-01 update:](#2022-09-01-update)- [🧸2022-08-17 update:](#2022-08-17-update)- [🕶2022-08-14 update:](#2022-08-14-update)- - [🎧2022-07-10 update:](#2022-07-10-update)- [相关项目(more)](#相关项目more)- [生态框架](#生态框架)- [常见问题 FAQ](#常见问题--faq)@@ -60,6 +60,10 @@- 基于百度的开源PaddleOCR 模型及训练,任何人可以使用本推理库,也可以根据自己的需求使用百度的paddlepaddle框架进行模型优化。## 近期更新([more](./docs/change_log.md))+#### 🛴2022-09-01 update:+- 由于openvino发布了2022.2.0.dev20220829版本,该版本解决了`cls`部分模型推理的问题。至此,基于openvino的rapidocr完成了统一,全部由openvino推理引擎完成。+- 详细使用方法参见:[python/README](./python/README.md#源码使用步骤)+#### 🧸2022-08-17 update:- python/ocrweb部分 v1.1.0发布,详情参见[v1.1.0](https://github.com/RapidAI/RapidOCR/releases/tag/v1.1.0)@@ -67,11 +71,6 @@- ocrweb部分增加以API方式部署调用的功能,可以通过发送POST请求,来获得OCR识别结果。- 详情参见:[API方式调用](./ocrweb/README.md#以api方式运行和调用)-#### 🎧2022-07-10 update:-- 添加onnxruntime-gpu的测试情况→[link](./python/README.md#onnxruntime-gpu版推理配置)-- 添加benchamark测试集 → [link](./images/README.md)-- 添加自动发布whl包的actions,当修改`python/rapidocr_onnxruntime`下代码时,会自动更新发布whl包。具体使用方法参见[Whl README](./docs/doc_whl_en.md)-## 相关项目([more](./docs/related_projects.md))- [RapidVideOCR](https://github.com/SWHL/RapidVideOCR):基于RapidOCR,提取视频中的硬字幕diff --git a/docs/README_en.md b/docs/README_en.mdindex cbe8cd6..7dc6d35 100644--- a/docs/README_en.md+++ b/docs/README_en.md@@ -25,9 +25,9 @@- [RapidOCR](#rapidocr)- [Introduction](#introduction)- [Recently updates(more)](#recently-updatesmore)+ - [🛴2022-09-01 update:](#2022-09-01-update)- [🧸2022-08-17 update:](#2022-08-17-update)- [🕶2022-08-14 update:](#2022-08-14-update)- - [🎧2022-07-10 update:](#2022-07-10-update)- [Overall Framework](#overall-framework)- [FAQ](#faq)- [SDK compilation status](#sdk-compilation-status)@@ -62,6 +62,10 @@- Based on Baidu's open source PaddleOCR model and training, anyone can use this inference library, or use Baidu's paddlepaddle framework for model optimization according to their own needs.## Recently updates([more](./change_log_en.md))+#### 🛴2022-09-01 update:+- Since openvino released version 2022.2.0.dev20220829, this version solves the problem of `cls` partial model inference. So far, the openvino-based rapidocr has been unified, and it is all completed by the openvino inference engine.+- For detailed usage, see: [python/README](../python/README.md#源码使用步骤).+#### 🧸2022-08-17 update:- The python/ocrweb part v1.1.0 is released, see the [link]((https://github.com/RapidAI/RapidOCR/releases/tag/v1.1.0)) for details.@@ -69,11 +73,6 @@- The ocrweb part adds the function of deploying calls by API, and you can send POST requests to get OCR recognition results.- For details, see: [API deploy](../ocrweb/README.md#以api方式运行和调用)-#### 🎧2022-07-10 update:-- Add test case for onnxruntime-gpu → [link](../python/README.md#onnxruntime-gpu version inference configuration)-- Add benchamark test set → [link](../images/README.md)-- Add actions to automatically publish whl packages, when modifying python/rapidocr_onnxruntime, it will automatically update the published whl packages. See [WHL README](../docs/doc_whl_en.md)-## Overall Framework```mermaiddiff --git a/docs/change_log.md b/docs/change_log.mdindex 541bdc5..0a9466c 100644--- a/docs/change_log.md+++ b/docs/change_log.md@@ -1,3 +1,7 @@+#### 🛴2022-09-01 update:+- 由于openvino发布了2022.2.0.dev20220829版本,该版本解决了`cls`部分模型推理的问题。至此,基于openvino的rapidocr完成了统一,全部由openvino推理引擎完成。+- 详细使用方法参见:[python/README](../python/README.md#源码使用步骤)+#### 🧸2022-08-17 update:- python/ocrweb部分 v1.1.0发布,详情参见[v1.1.0](https://github.com/RapidAI/RapidOCR/releases/tag/v1.1.0)diff --git a/docs/change_log_en.md b/docs/change_log_en.mdindex 2703acd..fcacae7 100644--- a/docs/change_log_en.md+++ b/docs/change_log_en.md@@ -1,3 +1,7 @@+#### 🛴2022-09-01 update:+- Since openvino released version 2022.2.0.dev20220829, this version solves the problem of `cls` partial model inference. So far, the openvino-based rapidocr has been unified, and it is all completed by the openvino inference engine.+- For detailed usage, see: [python/README](../python/README.md#源码使用步骤).+#### 🧸2022-08-17 update:- The python/ocrweb part v1.1.0 is released, see the [link]((https://github.com/RapidAI/RapidOCR/releases/tag/v1.1.0)) for details.diff --git a/python/README.md b/python/README.mdindex ad9633a..a7ee0c3 100755--- a/python/README.md+++ b/python/README.md@@ -46,7 +46,7 @@# 基于openvino引擎推理from rapidocr_openvino import TextSystem```-- 值得说明的是,基于openvino推理部分中`ch_ppocr_v2_cls`部分仍然是基于onnxruntime的,原因是openvino有bug,详情见[openvino/issue](https://github.com/openvinotoolkit/openvino/issues/11501)+- 关于openvino详细的使用方法,参见[openvino_readme](./rapidocr_openvino/README.md)。### pip安装快速使用1. 安装`rapidocr_onnxruntime`包@@ -154,7 +154,7 @@ print(rec_res)- 基于openvino推理所需环境安装:```bash# Windows端- pip install openvino==2022.1.0+ pip install openvino==2022.2.0.dev20220829pip install -r requirements.txt -i https://pypi.douban.com/simple/```diff --git a/python/rapidocr_openvino/README.md b/python/rapidocr_openvino/README.mdindex 7b97c65..f0c8b54 100644--- a/python/rapidocr_openvino/README.md+++ b/python/rapidocr_openvino/README.md@@ -1,12 +1,11 @@## rapidocr_openvino-**🚩注意:基于目前`openvino==2022.1.0`版,在推理批量图像时,存在申请内存不释放的问题,详情可参见[issue11939](https://github.com/openvinotoolkit/openvino/issues/11939)**+**🚩注意:基于目前`openvino==2022.2.0.dev20220829`版,在推理批量图像时,存在申请内存不释放的问题,详情可参见[issue11939](https://github.com/openvinotoolkit/openvino/issues/11939)**<details open><summary>目录</summary>- [rapidocr_openvino](#rapidocr_openvino)- - [基于OpenVINO推理引擎](#基于openvino推理引擎)- [安装](#安装)- [模型问题](#模型问题)- [关于OpenVINO](#关于openvino)@@ -14,17 +13,14 @@- [OpenVINO与ONNXRuntime推理代码写法对比](#openvino与onnxruntime推理代码写法对比)</details>-#### 基于OpenVINO推理引擎-- ~~OpenVINO推理方向分类模型有误,已经提了[issue](https://github.com/openvinotoolkit/openvino/issues/11501)~~-- 问题已经解决,但是需要自己编译OpenVINO,参见[Answer](https://github.com/openvinotoolkit/openvino/issues/11501#issuecomment-1096366363)#### 安装```bash# Windows端-pip install openvino==2022.1.0+pip install openvino==2022.2.0.dev20220829# 里面含有mo-pip install openvino-dev==2022.1.0+pip install openvino-dev==2022.2.0.dev20220829```#### 模型问题@@ -100,4 +96,3 @@ NOTE: 以`ch_ppocr_mobile_v2_det`中推理代码为例子vino_session.infer(inputs=[img])vino_preds = vino_session.get_output_tensor().data```-diff --git a/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py b/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.pyindex bdd6e17..fc7bd35 100644--- a/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py+++ b/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py@@ -21,9 +21,9 @@ import cv2import numpy as nptry:- from .utils import ClsPostProcess, read_yaml, OrtInferSession+ from .utils import ClsPostProcess, read_yaml, OpenVINOInferSessionexcept:- from utils import ClsPostProcess, read_yaml, OrtInferSession+ from utils import ClsPostProcess, read_yaml, OpenVINOInferSessionclass TextClassifier(object):@@ -33,9 +33,8 @@ class TextClassifier(object):self.cls_thresh = config['cls_thresh']self.postprocess_op = ClsPostProcess(config['label_list'])- session_instance = OrtInferSession(config)- self.session = session_instance.session- self.input_name = session_instance.get_input_name()+ openvino_instance = OpenVINOInferSession(config)+ self.session = openvino_instance.sessiondef __call__(self, img_list: List[np.ndarray]):if isinstance(img_list, np.ndarray):@@ -69,8 +68,9 @@ class TextClassifier(object):norm_img_batch = np.concatenate(norm_img_batch).astype(np.float32)starttime = time.time()- onnx_inputs = {self.input_name: norm_img_batch}- prob_out = self.session.run(None, onnx_inputs)[0]+ self.session.infer(inputs=[norm_img_batch])+ prob_out = self.session.get_output_tensor().data+cls_result = self.postprocess_op(prob_out)elapse += time.time() - starttimediff --git a/python/rapidocr_openvino/ch_ppocr_v2_cls/utils.py b/python/rapidocr_openvino/ch_ppocr_v2_cls/utils.pyindex 8ee0fa5..abcf3c3 100644--- a/python/rapidocr_openvino/ch_ppocr_v2_cls/utils.py+++ b/python/rapidocr_openvino/ch_ppocr_v2_cls/utils.py@@ -11,44 +11,16 @@# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.-import warnings-import yaml-from onnxruntime import (get_available_providers, get_device,- SessionOptions, InferenceSession)+from openvino.runtime import Core-class OrtInferSession(object):+class OpenVINOInferSession(object):def __init__(self, config):- sess_opt = SessionOptions()- sess_opt.log_severity_level = 4- sess_opt.enable_cpu_mem_arena = False-- cuda_ep = 'CUDAExecutionProvider'- cpu_ep = 'CPUExecutionProvider'-- EP_list = []- if config['use_cuda'] and get_device() == 'GPU' \- and cuda_ep in get_available_providers():- EP_list = [(cuda_ep, config[cuda_ep])]- EP_list.append(cpu_ep)-- self.session = InferenceSession(config['model_path'],- sess_options=sess_opt,- providers=EP_list)-- if config['use_cuda'] and cuda_ep not in self.session.get_providers():- warnings.warn(f'{cuda_ep} is not avaiable for current env, the inference part is automatically shifted to be executed under {cpu_ep}.\n'- 'Please ensure the installed onnxruntime-gpu version matches your cuda and cudnn version, '- 'you can check their relations from the offical web site: '- 'https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html',- RuntimeWarning)-- def get_input_name(self, input_idx=0):- return self.session.get_inputs()[input_idx].name-- def get_output_name(self, output_idx=0):- return self.session.get_outputs()[output_idx].name+ ie = Core()+ model_onnx = ie.read_model(config['model_path'])+ compile_model = ie.compile_model(model=model_onnx, device_name='CPU')+ self.session = compile_model.create_infer_request()def read_yaml(yaml_path):