Skip to content

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

Remove invalid code

SWHLcc96a2b00cbc
diff --git a/.github/workflows/gen_whl_to_pypi_rapidocr_ort.yml b/.github/workflows/gen_whl_to_pypi_rapidocr_ort.yml
index 5ca4f68..8578bb6 100644
--- a/.github/workflows/gen_whl_to_pypi_rapidocr_ort.yml
+++ b/.github/workflows/gen_whl_to_pypi_rapidocr_ort.yml
@@ -38,14 +38,13 @@ jobs:
DIR_NAME=${ZIP_NAME%.*}
unzip $DIR_NAME
cp $DIR_NAME/resources/models/*.onnx python/rapidocr_onnxruntime/models/
- cp $DIR_NAME/resources/models/*.onnx python/rapidocr_openvino/models/
cd python
pip install -r requirements_ort.txt
pip install pytest wheel get_pypi_latest_version openvino
cd tests
wget $TWO_DIM_IMAGE -O two_dim_image.npy
mv two_dim_image.npy test_files/
- pytest test_det.py test_cls.py test_rec.py test_all_ort.py
+ pytest test_ort.py
GenerateWHL_PushPyPi:
needs: UnitTesting
diff --git a/.github/workflows/gen_whl_to_pypi_rapidocr_vino.yml b/.github/workflows/gen_whl_to_pypi_rapidocr_vino.yml
index 5dec3d8..dff426a 100644
--- a/.github/workflows/gen_whl_to_pypi_rapidocr_vino.yml
+++ b/.github/workflows/gen_whl_to_pypi_rapidocr_vino.yml
@@ -37,7 +37,6 @@ jobs:
ZIP_NAME=${RESOURCES_URL##*/}
DIR_NAME=${ZIP_NAME%.*}
unzip $DIR_NAME
- cp $DIR_NAME/resources/models/*.onnx python/rapidocr_onnxruntime/models/
cp $DIR_NAME/resources/models/*.onnx python/rapidocr_openvino/models/
cd python
pip install -r requirements_vino.txt
@@ -45,7 +44,7 @@ jobs:
cd tests
wget $TWO_DIM_IMAGE -O two_dim_image.npy
mv two_dim_image.npy test_files/
- pytest test_det.py test_cls.py test_rec.py test_all_vino.py
+ pytest test_vino.py
GenerateWHL_PushPyPi:
needs: UnitTesting
diff --git a/python/demo.py b/python/demo.py
index 0792344..c191379 100644
--- a/python/demo.py
+++ b/python/demo.py
@@ -3,7 +3,10 @@
# @Contact: [email protected]
import cv2
-from rapidocr_onnxruntime import RapidOCR, VisRes
+from rapidocr_paddle import RapidOCR, VisRes
+
+# from rapidocr_onnxruntime import RapidOCR, VisRes
+
# from rapidocr_openvino import RapidOCR, VisRes
diff --git a/python/rapidocr_openvino/utils.py b/python/rapidocr_openvino/utils.py
index 0131397..f391045 100644
--- a/python/rapidocr_openvino/utils.py
+++ b/python/rapidocr_openvino/utils.py
@@ -22,7 +22,6 @@ class OpenVINOInferSession:
def __init__(self, config):
ie = Core()
- config["model_path"] = str(root_dir / config["model_path"])
self._verify_model(config["model_path"])
model_onnx = ie.read_model(config["model_path"])
compile_model = ie.compile_model(model=model_onnx, device_name="CPU")
diff --git a/python/requirements_ort.txt b/python/requirements_ort.txt
index 4111d1f..11e93fc 100644
--- a/python/requirements_ort.txt
+++ b/python/requirements_ort.txt
@@ -5,4 +5,4 @@ numpy>=1.19.5
six>=1.15.0
Shapely>=1.7.1
PyYAML
-Pillow
+Pillow<=9.5.0
diff --git a/python/requirements_vino.txt b/python/requirements_vino.txt
index 881bbd3..d6255f4 100644
--- a/python/requirements_vino.txt
+++ b/python/requirements_vino.txt
@@ -5,4 +5,4 @@ numpy>=1.19.5
six>=1.15.0
Shapely>=1.7.1
PyYAML
-Pillow
\ No newline at end of file
+Pillow<=9.5.0
\ No newline at end of file
diff --git a/python/tests/test_cls.py b/python/tests/test_cls.py
deleted file mode 100644
index a5ebd04..0000000
--- a/python/tests/test_cls.py
+++ /dev/null
@@ -1,28 +0,0 @@
-# -*- encoding: utf-8 -*-
-# @Author: SWHL
-# @Contact: [email protected]
-import cv2
-import pytest
-from base_module import BaseModule
-
-
- "package_name", [("rapidocr_onnxruntime"), ("rapidocr_openvino")]
-)
-def test_cls(package_name: str):
- module_name = "ch_ppocr_v2_cls"
- class_name = "TextClassifier"
-
- base = BaseModule(package_name=package_name)
- TextClassifier = base.init_module(module_name, class_name)
-
- yaml_path = base.package_dir / module_name / "config.yaml"
- config = base.read_yaml(str(yaml_path))
- config["model_path"] = str(base.package_dir / config["model_path"])
-
- text_cls = TextClassifier(config)
-
- img_path = base.tests_dir / "test_files" / "text_cls.jpg"
- img = cv2.imread(str(img_path))
- result = text_cls([img])
- assert result[1][0][0] == "180"
diff --git a/python/tests/test_det.py b/python/tests/test_det.py
deleted file mode 100644
index d7bd057..0000000
--- a/python/tests/test_det.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# -*- encoding: utf-8 -*-
-# @Author: SWHL
-# @Contact: [email protected]
-import cv2
-import pytest
-from base_module import BaseModule
-
-
[email protected]("package_name", ["rapidocr_onnxruntime", "rapidocr_openvino"])
-def test_det(package_name):
- module_name = "ch_ppocr_v3_det"
- class_name = "TextDetector"
-
- base = BaseModule(package_name)
- TextDetector = base.init_module(module_name, class_name)
-
- yaml_path = base.package_dir / module_name / "config.yaml"
- config = base.read_yaml(str(yaml_path))
- config["model_path"] = str(base.package_dir / config["model_path"])
-
- text_det = TextDetector(config)
- img_path = base.tests_dir / "test_files" / "text_det.jpg"
- img = cv2.imread(str(img_path))
- dt_boxes, elapse = text_det(img)
- assert dt_boxes.shape == (18, 4, 2)
diff --git a/python/tests/test_all_ort.py b/python/tests/test_ort.py
similarity index 67%
rename from python/tests/test_all_ort.py
rename to python/tests/test_ort.py
index 5b6ce74..86f48a3 100644
--- a/python/tests/test_all_ort.py
+++ b/python/tests/test_ort.py
@@ -7,6 +7,7 @@ from pathlib import Path
import cv2
import numpy as np
import pytest
+from base_module import BaseModule
root_dir = Path(__file__).resolve().parent.parent
sys.path.append(str(root_dir))
@@ -16,6 +17,7 @@ from rapidocr_onnxruntime import LoadImageError, RapidOCR
engine = RapidOCR()
tests_dir = root_dir / "tests" / "test_files"
img_path = tests_dir / "ch_en_num.jpg"
+package_name = "rapidocr_onnxruntime"
def test_only_det():
@@ -145,3 +147,59 @@ def test_input_three_ndim_one_channel():
assert result[0][1] == "正品促销"
assert len(result) == 16
+
+
+def test_det():
+ module_name = "ch_ppocr_v3_det"
+ class_name = "TextDetector"
+
+ base = BaseModule(package_name)
+ TextDetector = base.init_module(module_name, class_name)
+
+ yaml_path = base.package_dir / module_name / "config.yaml"
+ config = base.read_yaml(str(yaml_path))
+ config["model_path"] = str(base.package_dir / config["model_path"])
+
+ text_det = TextDetector(config)
+ img_path = base.tests_dir / "test_files" / "text_det.jpg"
+ img = cv2.imread(str(img_path))
+ dt_boxes, elapse = text_det(img)
+ assert dt_boxes.shape == (18, 4, 2)
+
+
+def test_cls():
+ module_name = "ch_ppocr_v2_cls"
+ class_name = "TextClassifier"
+
+ base = BaseModule(package_name=package_name)
+ TextClassifier = base.init_module(module_name, class_name)
+
+ yaml_path = base.package_dir / module_name / "config.yaml"
+ config = base.read_yaml(str(yaml_path))
+ config["model_path"] = str(base.package_dir / config["model_path"])
+
+ text_cls = TextClassifier(config)
+
+ img_path = base.tests_dir / "test_files" / "text_cls.jpg"
+ img = cv2.imread(str(img_path))
+ result = text_cls([img])
+ assert result[1][0][0] == "180"
+
+
+def test_rec():
+ module_name = "ch_ppocr_v3_rec"
+ class_name = "TextRecognizer"
+
+ base = BaseModule(package_name)
+ TextRecognizer = base.init_module(module_name, class_name)
+
+ yaml_path = base.package_dir / module_name / "config.yaml"
+ config = base.read_yaml(str(yaml_path))
+ config["model_path"] = str(base.package_dir / config["model_path"])
+
+ text_rec = TextRecognizer(config)
+
+ img_path = base.tests_dir / "test_files" / "text_rec.jpg"
+ img = cv2.imread(str(img_path))
+ rec_res, elapse = text_rec(img)
+ assert rec_res[0][0] == "ιŸ©ε›½ε°ι¦†"
diff --git a/python/tests/test_rec.py b/python/tests/test_rec.py
deleted file mode 100644
index ac94289..0000000
--- a/python/tests/test_rec.py
+++ /dev/null
@@ -1,26 +0,0 @@
-# -*- encoding: utf-8 -*-
-# @Author: SWHL
-# @Contact: [email protected]
-import cv2
-import pytest
-from base_module import BaseModule
-
-
[email protected]("package_name", ["rapidocr_onnxruntime", "rapidocr_openvino"])
-def test_det(package_name):
- module_name = "ch_ppocr_v3_rec"
- class_name = "TextRecognizer"
-
- base = BaseModule(package_name)
- TextRecognizer = base.init_module(module_name, class_name)
-
- yaml_path = base.package_dir / module_name / "config.yaml"
- config = base.read_yaml(str(yaml_path))
- config["model_path"] = str(base.package_dir / config["model_path"])
-
- text_rec = TextRecognizer(config)
-
- img_path = base.tests_dir / "test_files" / "text_rec.jpg"
- img = cv2.imread(str(img_path))
- rec_res, elapse = text_rec(img)
- assert rec_res[0][0] == "ιŸ©ε›½ε°ι¦†"
diff --git a/python/tests/test_all_vino.py b/python/tests/test_vino.py
similarity index 67%
rename from python/tests/test_all_vino.py
rename to python/tests/test_vino.py
index 612fe05..44528f1 100644
--- a/python/tests/test_all_vino.py
+++ b/python/tests/test_vino.py
@@ -7,6 +7,7 @@ from pathlib import Path
import cv2
import numpy as np
import pytest
+from base_module import BaseModule
root_dir = Path(__file__).resolve().parent.parent
sys.path.append(str(root_dir))
@@ -16,6 +17,7 @@ from rapidocr_openvino import LoadImageError, RapidOCR
engine = RapidOCR()
tests_dir = root_dir / "tests" / "test_files"
img_path = tests_dir / "ch_en_num.jpg"
+package_name = "rapidocr_openvino"
def test_only_det():
@@ -145,3 +147,59 @@ def test_input_three_ndim_one_channel():
assert result[0][1] == "正品促销"
assert len(result) == 16
+
+
+def test_det():
+ module_name = "ch_ppocr_v3_det"
+ class_name = "TextDetector"
+
+ base = BaseModule(package_name)
+ TextDetector = base.init_module(module_name, class_name)
+
+ yaml_path = base.package_dir / module_name / "config.yaml"
+ config = base.read_yaml(str(yaml_path))
+ config["model_path"] = str(base.package_dir / config["model_path"])
+
+ text_det = TextDetector(config)
+ img_path = base.tests_dir / "test_files" / "text_det.jpg"
+ img = cv2.imread(str(img_path))
+ dt_boxes, elapse = text_det(img)
+ assert dt_boxes.shape == (18, 4, 2)
+
+
+def test_cls():
+ module_name = "ch_ppocr_v2_cls"
+ class_name = "TextClassifier"
+
+ base = BaseModule(package_name=package_name)
+ TextClassifier = base.init_module(module_name, class_name)
+
+ yaml_path = base.package_dir / module_name / "config.yaml"
+ config = base.read_yaml(str(yaml_path))
+ config["model_path"] = str(base.package_dir / config["model_path"])
+
+ text_cls = TextClassifier(config)
+
+ img_path = base.tests_dir / "test_files" / "text_cls.jpg"
+ img = cv2.imread(str(img_path))
+ result = text_cls([img])
+ assert result[1][0][0] == "180"
+
+
+def test_rec():
+ module_name = "ch_ppocr_v3_rec"
+ class_name = "TextRecognizer"
+
+ base = BaseModule(package_name)
+ TextRecognizer = base.init_module(module_name, class_name)
+
+ yaml_path = base.package_dir / module_name / "config.yaml"
+ config = base.read_yaml(str(yaml_path))
+ config["model_path"] = str(base.package_dir / config["model_path"])
+
+ text_rec = TextRecognizer(config)
+
+ img_path = base.tests_dir / "test_files" / "text_rec.jpg"
+ img = cv2.imread(str(img_path))
+ rec_res, elapse = text_rec(img)
+ assert rec_res[0][0] == "ιŸ©ε›½ε°ι¦†"