Skip to content

Commit

Permalink
Fixed issue #161
Browse files Browse the repository at this point in the history
  • Loading branch information
SWHL committed Apr 7, 2024
1 parent c04e096 commit 182e54e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
14 changes: 6 additions & 8 deletions python/rapidocr_onnxruntime/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
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()
Expand Down
2 changes: 1 addition & 1 deletion python/rapidocr_onnxruntime/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
14 changes: 6 additions & 8 deletions python/rapidocr_openvino/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
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()
Expand Down
2 changes: 1 addition & 1 deletion python/rapidocr_openvino/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
14 changes: 6 additions & 8 deletions python/rapidocr_paddle/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
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()
Expand Down
2 changes: 1 addition & 1 deletion python/rapidocr_paddle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 182e54e

Please sign in to comment.