Skip to content

📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

Optim code.

SWHLc4f86236e3c3
diff --git a/ocrweb_multi/rapidocr/classify.py b/ocrweb_multi/rapidocr/classify.py
index 5e1ac33..5c2b37b 100644
--- a/ocrweb_multi/rapidocr/classify.py
+++ b/ocrweb_multi/rapidocr/classify.py
@@ -21,7 +21,7 @@ import numpy as np
from utils.utils import OrtInferSession
-class ClsPostProcess(object):
+class ClsPostProcess():
"""Convert between text-label and text-index"""
def __init__(self, label_list):
@@ -40,7 +40,7 @@ class ClsPostProcess(object):
return decode_out, label
-class TextClassifier(object):
+class TextClassifier():
def __init__(self, path, config):
self.cls_batch_num = config['batch_size']
self.cls_thresh = config['score_thresh']
diff --git a/ocrweb_multi/rapidocr/detect.py b/ocrweb_multi/rapidocr/detect.py
index 46d202a..136b0bf 100644
--- a/ocrweb_multi/rapidocr/detect.py
+++ b/ocrweb_multi/rapidocr/detect.py
@@ -21,7 +21,7 @@ from utils.utils import OrtInferSession
from .detect_process import DBPostProcess, create_operators, transform
-class TextDetector(object):
+class TextDetector():
def __init__(self, path, config):
self.preprocess_op = create_operators(config['pre_process'])
self.postprocess_op = DBPostProcess(**config['post_process'])
diff --git a/ocrweb_multi/rapidocr/detect_process.py b/ocrweb_multi/rapidocr/detect_process.py
index 0a01530..2b4307b 100644
--- a/ocrweb_multi/rapidocr/detect_process.py
+++ b/ocrweb_multi/rapidocr/detect_process.py
@@ -27,7 +27,7 @@ import six
from shapely.geometry import Polygon
-class DecodeImage(object):
+class DecodeImage():
"""decode image"""
def __init__(self, img_mode='RGB', channel_first=False):
@@ -62,7 +62,7 @@ class DecodeImage(object):
return data
-class NormalizeImage(object):
+class NormalizeImage():
"""normalize image such as substract mean, divide std"""
def __init__(self, scale=None, mean=None, std=None, order='chw'):
@@ -79,7 +79,7 @@ class NormalizeImage(object):
return data
-class ToCHWImage(object):
+class ToCHWImage():
"""convert hwc image to chw image"""
def __init__(self):
@@ -91,7 +91,7 @@ class ToCHWImage(object):
return data
-class KeepKeys(object):
+class KeepKeys():
def __init__(self, keep_keys):
self.keep_keys = keep_keys
@@ -102,7 +102,7 @@ class KeepKeys(object):
return data_list
-class DetResizeForTest(object):
+class DetResizeForTest():
def __init__(self, **kwargs):
super(DetResizeForTest, self).__init__()
self.resize_type = 0
@@ -247,7 +247,7 @@ def draw_text_det_res(dt_boxes, img_path):
return src_im
-class DBPostProcess(object):
+class DBPostProcess():
"""The post process for Differentiable Binarization (DB)."""
def __init__(
diff --git a/ocrweb_multi/rapidocr/rapid_ocr_api.py b/ocrweb_multi/rapidocr/rapid_ocr_api.py
index 479dcb4..d5bc8e8 100644
--- a/ocrweb_multi/rapidocr/rapid_ocr_api.py
+++ b/ocrweb_multi/rapidocr/rapid_ocr_api.py
@@ -61,7 +61,7 @@ def load_onnx_model(step, name):
return model_class(model_config['path'], model_config.get('config'))
-class RapidOCR(object):
+class RapidOCR():
def __init__(self, config):
super(RapidOCR).__init__()
self.config = config
@@ -134,7 +134,7 @@ class RapidOCR(object):
sorted boxes(array) with shape [4, 2]
"""
- class AlignBox(object):
+ class AlignBox():
def __init__(self, data) -> None:
self.data = data
self.x = data[0][0]
diff --git a/ocrweb_multi/rapidocr/recognize.py b/ocrweb_multi/rapidocr/recognize.py
index f77a6f2..ae14ff7 100644
--- a/ocrweb_multi/rapidocr/recognize.py
+++ b/ocrweb_multi/rapidocr/recognize.py
@@ -23,7 +23,7 @@ import numpy as np
from utils.utils import get_resource_path, OrtInferSession
-class CTCLabelDecode(object):
+class CTCLabelDecode():
"""Convert between text-label and text-index"""
def __init__(self, characters: List[str]):
@@ -86,7 +86,7 @@ class CTCLabelDecode(object):
return result_list
-class TextRecognizer(object):
+class TextRecognizer():
def __init__(self, path, config):
self.rec_batch_num = config.get('rec_batch_num', 6)
diff --git a/ocrweb_multi/utils/utils.py b/ocrweb_multi/utils/utils.py
index 948bbf5..f191611 100644
--- a/ocrweb_multi/utils/utils.py
+++ b/ocrweb_multi/utils/utils.py
@@ -27,7 +27,7 @@ def tojson(obj, **kws):
return json.dumps(obj, default=default, ensure_ascii=False, **kws) + '\n'
-class OrtInferSession(object):
+class OrtInferSession():
def __init__(self, model_path):
ort_conf = conf['global']
sess_opt = SessionOptions()
@@ -69,7 +69,7 @@ class OrtInferSession(object):
return self.session.get_outputs()[output_idx].name
-class Ticker(object):
+class Ticker():
def __init__(self, reset=True) -> None:
self.ts = time.perf_counter()
self.reset = reset
diff --git a/python/rapid_structure/docs/README_Layout.md b/python/rapid_structure/docs/README_Layout.md
index 16b0a4d..d860154 100644
--- a/python/rapid_structure/docs/README_Layout.md
+++ b/python/rapid_structure/docs/README_Layout.md
@@ -3,6 +3,7 @@
<a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
<a href="https://pypi.org/project/rapid-layout/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapid-layout?style=plastic"></a>
+ <a href="https://pypi.org/project/rapid-layout/"><img src="https://img.shields.io/pypi/dm/rapid-layout?color=9cf"></a>
</p>
##### 简介和说明
diff --git a/python/rapid_structure/docs/README_Table.md b/python/rapid_structure/docs/README_Table.md
index bc07a80..97ed4aa 100644
--- a/python/rapid_structure/docs/README_Table.md
+++ b/python/rapid_structure/docs/README_Table.md
@@ -3,10 +3,11 @@
<a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
<a href="https://pypi.org/project/rapid-table/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapid-table?style=plastic"></a>
+ <a href="https://pypi.org/project/rapid-table/"><img src="https://img.shields.io/pypi/dm/rapid-table?color=9cf"></a>
</p>
##### 简介和说明
-- 该部分主要是做文档类图像的表格结构还原。
+- 该部分主要是做文档类图像的表格结构还原。该包依赖`rapidocr_onnxruntime`。
- 具体来说,就是分析给定的表格图像,将表格还原为对应的html格式。
- 目前支持两种类别的表格识别模型:中文和英文表格识别模型,具体可参见下面表格:
diff --git a/python/rapid_structure/rapid_layout/utils.py b/python/rapid_structure/rapid_layout/utils.py
index 200a274..88a7f87 100644
--- a/python/rapid_structure/rapid_layout/utils.py
+++ b/python/rapid_structure/rapid_layout/utils.py
@@ -11,7 +11,7 @@ from onnxruntime import (get_available_providers, get_device,
GraphOptimizationLevel)
-class OrtInferSession(object):
+class OrtInferSession():
def __init__(self, config):
sess_opt = SessionOptions()
sess_opt.log_severity_level = 4
@@ -75,7 +75,7 @@ def create_operators(op_param_dict):
return ops
-class Resize(object):
+class Resize():
def __init__(self, size=(640, 640), **kwargs):
self.size = size
@@ -105,7 +105,7 @@ class Resize(object):
return data
-class NormalizeImage(object):
+class NormalizeImage():
""" normalize image such as substract mean, divide std
"""
@@ -129,7 +129,7 @@ class NormalizeImage(object):
return data
-class ToCHWImage(object):
+class ToCHWImage():
""" convert hwc image to chw image
"""
def __init__(self, **kwargs):
@@ -141,7 +141,7 @@ class ToCHWImage(object):
return data
-class KeepKeys(object):
+class KeepKeys():
def __init__(self, keep_keys, **kwargs):
self.keep_keys = keep_keys
@@ -158,7 +158,7 @@ def read_yaml(yaml_path):
return data
-class PicoDetPostProcess(object):
+class PicoDetPostProcess():
"""
Args:
input_shape (int): network input image size
diff --git a/python/rapid_structure/rapid_table/table_structure/table_structure.py b/python/rapid_structure/rapid_table/table_structure/table_structure.py
index fdc297d..2a96ecf 100644
--- a/python/rapid_structure/rapid_table/table_structure/table_structure.py
+++ b/python/rapid_structure/rapid_table/table_structure/table_structure.py
@@ -17,7 +17,7 @@ import numpy as np
from .utils import (OrtInferSession, TableLabelDecode, TablePreprocess)
-class TableStructurer(object):
+class TableStructurer():
def __init__(self, model_path: str):
self.preprocess_op = TablePreprocess()
diff --git a/python/rapid_structure/rapid_table/table_structure/utils.py b/python/rapid_structure/rapid_table/table_structure/utils.py
index 80edcf0..ada948c 100644
--- a/python/rapid_structure/rapid_table/table_structure/utils.py
+++ b/python/rapid_structure/rapid_table/table_structure/utils.py
@@ -22,7 +22,7 @@ from onnxruntime import (GraphOptimizationLevel, InferenceSession,
SessionOptions)
-class OrtInferSession(object):
+class OrtInferSession():
def __init__(self, onnx_path: str):
self.__verify_model(onnx_path)
@@ -59,7 +59,7 @@ class OrtInferSession(object):
raise FileExistsError(f'{model_path} is not a file.')
-class TableLabelDecode(object):
+class TableLabelDecode():
""" """
def __init__(self,
dict_character,
@@ -192,7 +192,7 @@ class TableLabelDecode(object):
return dict_character
-class TablePreprocess(object):
+class TablePreprocess():
def __init__(self):
self.table_max_len = 488
self.build_pre_process_list()
@@ -249,7 +249,7 @@ class TablePreprocess(object):
]
-class ResizeTableImage(object):
+class ResizeTableImage():
def __init__(self, max_len, resize_bboxes=False, infer_mode=False,
**kwargs):
super(ResizeTableImage, self).__init__()
@@ -273,7 +273,7 @@ class ResizeTableImage(object):
return data
-class PaddingTableImage(object):
+class PaddingTableImage():
def __init__(self, size, **kwargs):
super(PaddingTableImage, self).__init__()
self.size = size
@@ -291,10 +291,9 @@ class PaddingTableImage(object):
return data
-class NormalizeImage(object):
+class NormalizeImage():
""" normalize image such as substract mean, divide std
"""
-
def __init__(self, scale=None, mean=None, std=None, order='chw', **kwargs):
if isinstance(scale, str):
scale = eval(scale)
@@ -307,10 +306,7 @@ class NormalizeImage(object):
self.std = np.array(std).reshape(shape).astype('float32')
def __call__(self, data):
- img = data['image']
- from PIL import Image
- if isinstance(img, Image.Image):
- img = np.array(img)
+ img = np.array(data['image'])
assert isinstance(img,
np.ndarray), "invalid input 'img' in NormalizeImage"
data['image'] = (
@@ -318,23 +314,19 @@ class NormalizeImage(object):
return data
-class ToCHWImage(object):
+class ToCHWImage():
""" convert hwc image to chw image
"""
-
def __init__(self, **kwargs):
pass
def __call__(self, data):
- img = data['image']
- from PIL import Image
- if isinstance(img, Image.Image):
- img = np.array(img)
+ img = np.array(data['image'])
data['image'] = img.transpose((2, 0, 1))
return data
-class KeepKeys(object):
+class KeepKeys():
def __init__(self, keep_keys, **kwargs):
self.keep_keys = keep_keys
diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/text_cls.py b/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/text_cls.py
index 6ea2e4b..3d2b673 100644
--- a/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/text_cls.py
+++ b/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/text_cls.py
@@ -26,7 +26,7 @@ except:
from utils import ClsPostProcess, read_yaml, OrtInferSession
-class TextClassifier(object):
+class TextClassifier():
def __init__(self, config):
self.cls_image_shape = config['cls_image_shape']
self.cls_batch_num = config['cls_batch_num']
diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py b/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py
index b37a8be..d37221e 100644
--- a/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py
+++ b/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py
@@ -21,7 +21,7 @@ from onnxruntime import (get_available_providers, get_device,
root_dir = Path(__file__).resolve().parent.parent
-class OrtInferSession(object):
+class OrtInferSession():
def __init__(self, config):
sess_opt = SessionOptions()
sess_opt.log_severity_level = 4
@@ -74,7 +74,7 @@ def read_yaml(yaml_path):
return data
-class ClsPostProcess(object):
+class ClsPostProcess():
""" Convert between text-label and text-index """
def __init__(self, label_list):
diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py b/python/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py
index d6511b1..dc7eccd 100644
--- a/python/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py
+++ b/python/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py
@@ -32,7 +32,7 @@ from shapely.geometry import Polygon
root_dir = Path(__file__).resolve().parent.parent
-class OrtInferSession(object):
+class OrtInferSession():
def __init__(self, config):
sess_opt = SessionOptions()
sess_opt.log_severity_level = 4
@@ -85,7 +85,7 @@ def read_yaml(yaml_path):
return data
-class DecodeImage(object):
+class DecodeImage():
""" decode image """
def __init__(self, img_mode='RGB', channel_first=False):
@@ -116,7 +116,7 @@ class DecodeImage(object):
return data
-class NormalizeImage(object):
+class NormalizeImage():
""" normalize image such as substract mean, divide std"""
def __init__(self, scale=None, mean=None, std=None, order='chw'):
@@ -136,21 +136,18 @@ class NormalizeImage(object):
return data
-class ToCHWImage(object):
+class ToCHWImage():
""" convert hwc image to chw image"""
def __init__(self):
pass
def __call__(self, data):
- img = data['image']
- from PIL import Image
- if isinstance(img, Image.Image):
- img = np.array(img)
+ img = np.array(data['image'])
data['image'] = img.transpose((2, 0, 1))
return data
-class KeepKeys(object):
+class KeepKeys():
def __init__(self, keep_keys):
self.keep_keys = keep_keys
@@ -161,7 +158,7 @@ class KeepKeys(object):
return data_list
-class DetResizeForTest(object):
+class DetResizeForTest():
def __init__(self, **kwargs):
super(DetResizeForTest, self).__init__()
self.resize_type = 0
@@ -308,7 +305,7 @@ def draw_text_det_res(dt_boxes, img_path):
return src_im
-class DBPostProcess(object):
+class DBPostProcess():
"""The post process for Differentiable Binarization (DB)."""
def __init__(self,
diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py b/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
index df1bda0..116eabb 100644
--- a/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
+++ b/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
@@ -25,7 +25,7 @@ except:
from utils import CTCLabelDecode, read_yaml, OrtInferSession
-class TextRecognizer(object):
+class TextRecognizer():
def __init__(self, config):
session_instance = OrtInferSession(config)
self.session = session_instance.session
diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py b/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
index 0860460..8d04f25 100644
--- a/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
+++ b/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
@@ -12,7 +12,7 @@ from onnxruntime import (GraphOptimizationLevel, InferenceSession,
root_dir = Path(__file__).resolve().parent.parent
-class OrtInferSession(object):
+class OrtInferSession():
def __init__(self, config):
sess_opt = SessionOptions()
sess_opt.log_severity_level = 4
@@ -74,7 +74,7 @@ def read_yaml(yaml_path):
return data
-class CTCLabelDecode(object):
+class CTCLabelDecode():
""" Convert between text-label and text-index """
def __init__(self, character_dict_path):
diff --git a/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py b/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py
index 1c5bf19..ed1fc17 100644
--- a/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py
+++ b/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py
@@ -26,7 +26,7 @@ except:
from utils import ClsPostProcess, read_yaml, OpenVINOInferSession
-class TextClassifier(object):
+class TextClassifier():
def __init__(self, config):
self.cls_image_shape = config['cls_image_shape']
self.cls_batch_num = config['cls_batch_num']
diff --git a/python/rapidocr_openvino/ch_ppocr_v2_cls/utils.py b/python/rapidocr_openvino/ch_ppocr_v2_cls/utils.py
index 08fae56..0f2f666 100644
--- a/python/rapidocr_openvino/ch_ppocr_v2_cls/utils.py
+++ b/python/rapidocr_openvino/ch_ppocr_v2_cls/utils.py
@@ -19,7 +19,7 @@ from openvino.runtime import Core
root_dir = Path(__file__).resolve().parent.parent
-class OpenVINOInferSession(object):
+class OpenVINOInferSession():
def __init__(self, config):
ie = Core()
@@ -44,7 +44,7 @@ def read_yaml(yaml_path):
return data
-class ClsPostProcess(object):
+class ClsPostProcess():
""" Convert between text-label and text-index """
def __init__(self, label_list):
diff --git a/python/rapidocr_openvino/ch_ppocr_v3_det/text_detect.py b/python/rapidocr_openvino/ch_ppocr_v3_det/text_detect.py
index 108b62a..d4b6341 100644
--- a/python/rapidocr_openvino/ch_ppocr_v3_det/text_detect.py
+++ b/python/rapidocr_openvino/ch_ppocr_v3_det/text_detect.py
@@ -26,7 +26,7 @@ except:
transform, OpenVINOInferSession)
-class TextDetector(object):
+class TextDetector():
def __init__(self, config):
self.preprocess_op = create_operators(config['pre_process'])
self.postprocess_op = DBPostProcess(**config['post_process'])
diff --git a/python/rapidocr_openvino/ch_ppocr_v3_det/utils.py b/python/rapidocr_openvino/ch_ppocr_v3_det/utils.py
index 0e2888a..b7795ee 100644
--- a/python/rapidocr_openvino/ch_ppocr_v3_det/utils.py
+++ b/python/rapidocr_openvino/ch_ppocr_v3_det/utils.py
@@ -30,7 +30,7 @@ from shapely.geometry import Polygon
root_dir = Path(__file__).resolve().parent.parent
-class OpenVINOInferSession(object):
+class OpenVINOInferSession():
def __init__(self, config):
ie = Core()
@@ -55,7 +55,7 @@ def read_yaml(yaml_path):
return data
-class DecodeImage(object):
+class DecodeImage():
""" decode image """
def __init__(self, img_mode='RGB', channel_first=False):
@@ -86,7 +86,7 @@ class DecodeImage(object):
return data
-class NormalizeImage(object):
+class NormalizeImage():
""" normalize image such as substract mean, divide std"""
def __init__(self, scale=None, mean=None, std=None, order='chw'):
@@ -106,21 +106,18 @@ class NormalizeImage(object):
return data
-class ToCHWImage(object):
+class ToCHWImage():
""" convert hwc image to chw image"""
def __init__(self):
pass
def __call__(self, data):
- img = data['image']
- from PIL import Image
- if isinstance(img, Image.Image):
- img = np.array(img)
+ img = np.array(data['image'])
data['image'] = img.transpose((2, 0, 1))
return data
-class KeepKeys(object):
+class KeepKeys():
def __init__(self, keep_keys):
self.keep_keys = keep_keys
@@ -131,7 +128,7 @@ class KeepKeys(object):
return data_list
-class DetResizeForTest(object):
+class DetResizeForTest():
def __init__(self, **kwargs):
super(DetResizeForTest, self).__init__()
self.resize_type = 0
@@ -277,7 +274,7 @@ def draw_text_det_res(dt_boxes, img_path):
return src_im
-class DBPostProcess(object):
+class DBPostProcess():
"""The post process for Differentiable Binarization (DB)."""
def __init__(self,
diff --git a/python/rapidocr_openvino/ch_ppocr_v3_rec/text_recognize.py b/python/rapidocr_openvino/ch_ppocr_v3_rec/text_recognize.py
index ece6ea5..76a1ec6 100644
--- a/python/rapidocr_openvino/ch_ppocr_v3_rec/text_recognize.py
+++ b/python/rapidocr_openvino/ch_ppocr_v3_rec/text_recognize.py
@@ -29,7 +29,7 @@ except:
from utils import CTCLabelDecode, OpenVINOInferSession
-class TextRecognizer(object):
+class TextRecognizer():
def __init__(self, config):
self.rec_image_shape = config['rec_img_shape']
self.rec_batch_num = config['rec_batch_num']
diff --git a/python/rapidocr_openvino/ch_ppocr_v3_rec/utils.py b/python/rapidocr_openvino/ch_ppocr_v3_rec/utils.py
index 2e23ce0..bc18976 100644
--- a/python/rapidocr_openvino/ch_ppocr_v3_rec/utils.py
+++ b/python/rapidocr_openvino/ch_ppocr_v3_rec/utils.py
@@ -10,7 +10,7 @@ from openvino.runtime import Core
root_dir = Path(__file__).resolve().parent.parent
-class OpenVINOInferSession(object):
+class OpenVINOInferSession():
def __init__(self, config):
ie = Core()
@@ -35,7 +35,7 @@ def read_yaml(yaml_path):
return data
-class CTCLabelDecode(object):
+class CTCLabelDecode():
""" Convert between text-label and text-index """
def __init__(self, character_dict_path):
diff --git a/python/tests/base_module.py b/python/tests/base_module.py
index 6cc2001..b6c7e18 100644
--- a/python/tests/base_module.py
+++ b/python/tests/base_module.py
@@ -8,7 +8,7 @@ from pathlib import Path
import yaml
-class BaseModule(object):
+class BaseModule():
def __init__(self, package_name: str = 'rapidocr_onnxruntime'):
self.package_name = package_name
self.root_dir = Path(__file__).resolve().parent.parent