π Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
feat(inference): add get_character_list abstract method to InferSession
SWHLe549f7eacc22
diff --git a/python/rapidocr/inference_engine/base.py b/python/rapidocr/inference_engine/base.pyindex 6bf6ca7..6edaa89 100644--- a/python/rapidocr/inference_engine/base.py+++ b/python/rapidocr/inference_engine/base.py@@ -5,7 +5,7 @@ import abcfrom dataclasses import dataclassfrom enum import Enumfrom pathlib import Path-from typing import Dict, Union+from typing import Dict, List, Unionimport numpy as npfrom omegaconf import OmegaConf@@ -109,6 +109,10 @@ class InferSession(abc.ABC):def have_key(self, key: str = "character") -> bool:pass+ @abc.abstractmethod+ def get_character_list(self, key: str = "character") -> List[str]:+ pass+@classmethoddef get_model_url(cls, file_info: FileInfo) -> Dict[str, str]:engine_type = file_info.engine_type.valuediff --git a/python/rapidocr/inference_engine/mnn/main.py b/python/rapidocr/inference_engine/mnn/main.pyindex 09934d4..baef27d 100644--- a/python/rapidocr/inference_engine/mnn/main.py+++ b/python/rapidocr/inference_engine/mnn/main.py@@ -3,6 +3,7 @@# @Contact: [email protected]import tracebackfrom pathlib import Path+from typing import Listimport MNNimport numpy as np@@ -74,6 +75,9 @@ class MNNInferSession(InferSession):def have_key(self, key: str = "character") -> bool:return False+ def get_character_list(self, key: str = "character") -> List[str]:+ return []+class MNNError(Exception):passdiff --git a/python/rapidocr/inference_engine/paddle/main.py b/python/rapidocr/inference_engine/paddle/main.pyindex e2a04f3..e6f8b71 100644--- a/python/rapidocr/inference_engine/paddle/main.py+++ b/python/rapidocr/inference_engine/paddle/main.py@@ -2,7 +2,7 @@# @Author: SWHL# @Contact: [email protected]from pathlib import Path-from typing import Optional, Tuple+from typing import List, Optional, Tupleimport numpy as npfrom omegaconf.errors import ConfigKeyError@@ -142,6 +142,9 @@ class PaddleInferSession(InferSession):def have_key(self, key: str = "character") -> bool:return False+ def get_character_list(self, key: str = "character") -> List[str]:+ return []+class PaddleInferError(Exception):passdiff --git a/python/rapidocr/inference_engine/pytorch/main.py b/python/rapidocr/inference_engine/pytorch/main.pyindex 8dc7a6b..6da3dd5 100644--- a/python/rapidocr/inference_engine/pytorch/main.py+++ b/python/rapidocr/inference_engine/pytorch/main.py@@ -1,6 +1,8 @@# -*- encoding: utf-8 -*-# @Author: SWHL# @Contact: [email protected]+from typing import List+import numpy as npimport torch@@ -24,6 +26,9 @@ class TorchInferSession(InferSession):def have_key(self, key: str = "character") -> bool:return False+ def get_character_list(self, key: str = "character") -> List[str]:+ return []+class TorchInferError(Exception):passdiff --git a/python/rapidocr/inference_engine/tensorrt/main.py b/python/rapidocr/inference_engine/tensorrt/main.pyindex 6b636a7..121264e 100644--- a/python/rapidocr/inference_engine/tensorrt/main.py+++ b/python/rapidocr/inference_engine/tensorrt/main.py@@ -24,13 +24,14 @@ Example:>>> with TRTInferSession(config) as session:... output = session(input_array)"""+import tracebackfrom pathlib import Path-from typing import Any, Dict, Optional+from typing import Any, Dict, List, Optionalimport numpy as np-from cuda.bindings import runtime as cudartimport tensorrt as trt+from cuda.bindings import runtime as cudartfrom ...utils.download_file import DownloadFile, DownloadFileInputfrom ...utils.log import logger@@ -101,7 +102,9 @@ class TRTInferSession(InferSession):self._requires_square_input = self._check_multi_model(cfg)if self._requires_square_input:self._max_square_size = self._get_max_profile_size()- logger.debug(f"MULTI det model: requires square input, max_size={self._max_square_size}")+ logger.debug(+ f"MULTI det model: requires square input, max_size={self._max_square_size}"+ )else:self._requires_square_input = Falseself._max_square_size = 2048@@ -317,8 +320,9 @@ class TRTInferSession(InferSession):"""try:from ...utils.typings import LangDet, TaskType- is_det = getattr(cfg, 'task_type', None) == TaskType.DET- is_multi = getattr(cfg, 'lang_type', None) == LangDet.MULTI++ is_det = getattr(cfg, "task_type", None) == TaskType.DET+ is_multi = getattr(cfg, "lang_type", None) == LangDet.MULTIreturn is_det and is_multiexcept Exception:return False@@ -580,6 +584,9 @@ class TRTInferSession(InferSession):"""return False+ def get_character_list(self, key: str = "character") -> List[str]:+ return []+@classmethoddef get_dict_key_url(cls, file_info: FileInfo) -> Optional[str]:"""Get dictionary URL by falling back to Paddle/ONNX model config.