Skip to content

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

Fixed issue #161

SWHL182e54ef6d70
diff --git a/python/rapidocr_onnxruntime/main.py b/python/rapidocr_onnxruntime/main.py
index feb63e2..410639f 100644
--- a/python/rapidocr_onnxruntime/main.py
+++ b/python/rapidocr_onnxruntime/main.py
@@ -15,24 +15,22 @@ from .utils import (
LoadImage,
UpdateParameters,
VisRes,
- concat_model_path,
init_args,
read_yaml,
+ update_model_path,
)
root_dir = Path(__file__).resolve().parent
+DEFAULT_CFG_PATH = root_dir / "config.yaml"
class RapidOCR:
def __init__(self, config_path: Optional[str] = None, **kwargs):
- if config_path is None:
- config_path = str(root_dir / "config.yaml")
+ config = read_yaml(DEFAULT_CFG_PATH)
+ config = update_model_path(config)
- if not Path(config_path).exists():
- raise FileExistsError(f"{config_path} does not exist!")
-
- config = read_yaml(config_path)
- config = concat_model_path(config)
+ if config_path is not None and Path(config_path).exists:
+ config = read_yaml(config_path)
if kwargs:
updater = UpdateParameters()
diff --git a/python/rapidocr_onnxruntime/utils.py b/python/rapidocr_onnxruntime/utils.py
index 6bd46f4..ef60ed2 100644
--- a/python/rapidocr_onnxruntime/utils.py
+++ b/python/rapidocr_onnxruntime/utils.py
@@ -232,7 +232,7 @@ def read_yaml(yaml_path):
return data
-def concat_model_path(config):
+def update_model_path(config):
key = "model_path"
config["Det"][key] = str(root_dir / config["Det"][key])
config["Rec"][key] = str(root_dir / config["Rec"][key])
diff --git a/python/rapidocr_openvino/main.py b/python/rapidocr_openvino/main.py
index feb63e2..410639f 100644
--- a/python/rapidocr_openvino/main.py
+++ b/python/rapidocr_openvino/main.py
@@ -15,24 +15,22 @@ from .utils import (
LoadImage,
UpdateParameters,
VisRes,
- concat_model_path,
init_args,
read_yaml,
+ update_model_path,
)
root_dir = Path(__file__).resolve().parent
+DEFAULT_CFG_PATH = root_dir / "config.yaml"
class RapidOCR:
def __init__(self, config_path: Optional[str] = None, **kwargs):
- if config_path is None:
- config_path = str(root_dir / "config.yaml")
+ config = read_yaml(DEFAULT_CFG_PATH)
+ config = update_model_path(config)
- if not Path(config_path).exists():
- raise FileExistsError(f"{config_path} does not exist!")
-
- config = read_yaml(config_path)
- config = concat_model_path(config)
+ if config_path is not None and Path(config_path).exists:
+ config = read_yaml(config_path)
if kwargs:
updater = UpdateParameters()
diff --git a/python/rapidocr_openvino/utils.py b/python/rapidocr_openvino/utils.py
index 1e9171b..c5e0081 100644
--- a/python/rapidocr_openvino/utils.py
+++ b/python/rapidocr_openvino/utils.py
@@ -159,7 +159,7 @@ def read_yaml(yaml_path):
return data
-def concat_model_path(config):
+def update_model_path(config):
key = "model_path"
config["Det"][key] = str(root_dir / config["Det"][key])
config["Rec"][key] = str(root_dir / config["Rec"][key])
diff --git a/python/rapidocr_paddle/main.py b/python/rapidocr_paddle/main.py
index feb63e2..410639f 100644
--- a/python/rapidocr_paddle/main.py
+++ b/python/rapidocr_paddle/main.py
@@ -15,24 +15,22 @@ from .utils import (
LoadImage,
UpdateParameters,
VisRes,
- concat_model_path,
init_args,
read_yaml,
+ update_model_path,
)
root_dir = Path(__file__).resolve().parent
+DEFAULT_CFG_PATH = root_dir / "config.yaml"
class RapidOCR:
def __init__(self, config_path: Optional[str] = None, **kwargs):
- if config_path is None:
- config_path = str(root_dir / "config.yaml")
+ config = read_yaml(DEFAULT_CFG_PATH)
+ config = update_model_path(config)
- if not Path(config_path).exists():
- raise FileExistsError(f"{config_path} does not exist!")
-
- config = read_yaml(config_path)
- config = concat_model_path(config)
+ if config_path is not None and Path(config_path).exists:
+ config = read_yaml(config_path)
if kwargs:
updater = UpdateParameters()
diff --git a/python/rapidocr_paddle/utils.py b/python/rapidocr_paddle/utils.py
index 1baad84..0f7ac32 100644
--- a/python/rapidocr_paddle/utils.py
+++ b/python/rapidocr_paddle/utils.py
@@ -241,7 +241,7 @@ def read_yaml(yaml_path):
return data
-def concat_model_path(config):
+def update_model_path(config):
key = "model_path"
config["Det"][key] = str(root_dir / config["Det"][key])
config["Rec"][key] = str(root_dir / config["Rec"][key])