Skip to content

Commit

Permalink
Merge pull request #163 from breezedeus/dev
Browse files Browse the repository at this point in the history
Bugfix: Resolved issues related to serialization errors when handling ONNX Runtime session options by ensuring that non-serializable configurations are managed appropriately.
  • Loading branch information
breezedeus authored Dec 11, 2024
2 parents acbac46 + a839a6e commit 416ff1e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
11 changes: 11 additions & 0 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Release Notes

# Update 2024.12.11: **V1.1.2.2** Released

Major Changes:

- Bugfix: Resolved issues related to serialization errors when handling ONNX Runtime session options by ensuring that non-serializable configurations are managed appropriately.

主要变更:

- 修复了与 ONNX Runtime session options 相关的序列化错误,通过确保不可序列化的配置信息在适当的管理下进行处理。


# Update 2024.12.02: **V1.1.2.1** Released

Major Changes:
Expand Down
2 changes: 1 addition & 1 deletion pix2text/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# [Pix2Text](https://github.com/breezedeus/pix2text): an Open-Source Alternative to Mathpix.
# Copyright (C) 2022-2024, [Breezedeus](https://www.breezedeus.com).

__version__ = '1.1.2.1'
__version__ = '1.1.2.2'
5 changes: 3 additions & 2 deletions pix2text/ocr_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# [Pix2Text](https://github.com/breezedeus/pix2text): an Open-Source Alternative to Mathpix.
# Copyright (C) 2022-2024, [Breezedeus](https://www.breezedeus.com).
import string
from copy import deepcopy
from typing import Sequence, List, Optional

import numpy as np
import cv2

from .utils import custom_deepcopy


def clip(x, min_value, max_value):
return min(max(x, min_value), max_value)
Expand Down Expand Up @@ -176,7 +177,7 @@ def ocr(


def prepare_ocr_engine(languages: Sequence[str], ocr_engine_config):
ocr_engine_config = deepcopy(ocr_engine_config) if ocr_engine_config else {}
ocr_engine_config = custom_deepcopy(ocr_engine_config) if ocr_engine_config else {}
if len(set(languages).difference({'en', 'ch_sim'})) == 0:
from cnocr import CnOcr

Expand Down
7 changes: 4 additions & 3 deletions pix2text/text_formula_ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from spellchecker import SpellChecker

from .utils import (
custom_deepcopy,
sort_boxes,
merge_adjacent_bboxes,
adjust_line_height,
Expand Down Expand Up @@ -83,7 +84,7 @@ def __init__(
**kwargs ():
"""
if text_ocr is None:
text_config = deepcopy(DEFAULT_CONFIGS['text'])
text_config = custom_deepcopy(DEFAULT_CONFIGS['text'])
device = select_device(device=None)
text_config['context'] = device
logger.warning(
Expand Down Expand Up @@ -168,8 +169,8 @@ def prepare_configs(
):
def _to_default(_conf, _def_val):
if not _conf:
_conf = deepcopy(_def_val)
return deepcopy(_conf)
_conf = custom_deepcopy(_def_val)
return custom_deepcopy(_conf)

mfd_config = _to_default(mfd_config, DEFAULT_CONFIGS['mfd'])
mfd_config['device'] = device
Expand Down
16 changes: 16 additions & 0 deletions pix2text/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ def set_logger(log_file=None, log_level=logging.INFO, log_file_level=logging.NOT
return logger


def custom_deepcopy(value):
if isinstance(value, dict):
return {key: custom_deepcopy(val) for key, val in value.items()}
elif isinstance(value, list):
return [custom_deepcopy(item) for item in value]
elif isinstance(value, tuple):
return tuple([custom_deepcopy(item) for item in value])
elif isinstance(value, set):
return set([custom_deepcopy(item) for item in value])
else:
try:
return deepcopy(value)
except TypeError:
return value # Return the original value if it cannot be deep copied


def select_device(device) -> str:
if device is not None:
return device
Expand Down

0 comments on commit 416ff1e

Please sign in to comment.