first commit
Some checks are pending
Build/Publish Develop Docs / deploy (push) Waiting to run

This commit is contained in:
2025-07-02 08:57:16 +03:00
commit 56532cc9a9
1901 changed files with 457695 additions and 0 deletions

0
tests/models/__init__.py Normal file
View File

View File

@@ -0,0 +1,9 @@
def check_result_item_keys(result_item):
assert result_item.keys() == {
"input_path",
"page_index",
"input_img",
"class_ids",
"scores",
"label_names",
}

View File

@@ -0,0 +1,7 @@
def check_result_item_keys(result_item):
assert result_item.keys() == {
"input_path",
"page_index",
"input_img",
"boxes",
}

View File

@@ -0,0 +1,23 @@
import pytest
from paddleocr import DocImgOrientationClassification
from ..testing_utils import TEST_DATA_DIR, check_simple_inference_result
from .image_classification_common import check_result_item_keys
@pytest.fixture(scope="module")
def doc_img_orientation_classification_predictor():
return DocImgOrientationClassification()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "book_rot180.jpg",
],
)
def test_predict(doc_img_orientation_classification_predictor, image_path):
result = doc_img_orientation_classification_predictor.predict(str(image_path))
check_simple_inference_result(result)
check_result_item_keys(result[0])

View File

@@ -0,0 +1,53 @@
import pytest
from paddleocr import DocVLM
from ..testing_utils import (
TEST_DATA_DIR,
check_simple_inference_result,
check_wrapper_simple_inference_param_forwarding,
)
@pytest.fixture(scope="module")
def doc_vlm_predictor():
return DocVLM()
@pytest.mark.resource_intensive
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "medal_table.png",
],
)
def test_predict(doc_vlm_predictor, image_path):
result = doc_vlm_predictor.predict(str(image_path))
check_simple_inference_result(result)
assert result[0].keys() == {
"input_path",
"page_index",
"input_img",
"result",
}
@pytest.mark.resource_intensive
@pytest.mark.parametrize(
"params",
[
{},
],
)
def test_predict_params(
monkeypatch,
doc_vlm_predictor,
params,
):
check_wrapper_simple_inference_param_forwarding(
monkeypatch,
doc_vlm_predictor,
"paddlex_predictor",
"dummy_path",
params,
)

View File

@@ -0,0 +1,51 @@
import pytest
from paddleocr import FormulaRecognition
from ..testing_utils import (
TEST_DATA_DIR,
check_simple_inference_result,
check_wrapper_simple_inference_param_forwarding,
)
@pytest.fixture(scope="module")
def formula_recognition_predictor():
return FormulaRecognition()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "formula.png",
],
)
def test_predict(formula_recognition_predictor, image_path):
result = formula_recognition_predictor.predict(str(image_path))
check_simple_inference_result(result)
assert result[0].keys() == {
"input_path",
"page_index",
"input_img",
"rec_formula",
}
@pytest.mark.parametrize(
"params",
[
{},
],
)
def test_predict_params(
monkeypatch,
formula_recognition_predictor,
params,
):
check_wrapper_simple_inference_param_forwarding(
monkeypatch,
formula_recognition_predictor,
"paddlex_predictor",
"dummy_path",
params,
)

View File

@@ -0,0 +1,51 @@
import pytest
from paddleocr import LayoutDetection
from ..testing_utils import (
TEST_DATA_DIR,
check_simple_inference_result,
check_wrapper_simple_inference_param_forwarding,
)
from .object_detection_common import check_result_item_keys
@pytest.fixture(scope="module")
def layout_detection_predictor():
return LayoutDetection()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "doc_with_formula.png",
],
)
def test_predict(layout_detection_predictor, image_path):
result = layout_detection_predictor.predict(str(image_path))
check_simple_inference_result(result)
check_result_item_keys(result[0])
@pytest.mark.parametrize(
"params",
[
{"img_size": 640},
{"threshold": 0.5},
{"layout_nms": True},
{"layout_unclip_ratio": True},
{"layout_merge_bboxes_mode": True},
],
)
def test_predict_params(
monkeypatch,
layout_detection_predictor,
params,
):
check_wrapper_simple_inference_param_forwarding(
monkeypatch,
layout_detection_predictor,
"paddlex_predictor",
"dummy_path",
params,
)

View File

@@ -0,0 +1,55 @@
import pytest
from paddleocr import SealTextDetection
from ..testing_utils import (
TEST_DATA_DIR,
check_simple_inference_result,
check_wrapper_simple_inference_param_forwarding,
)
@pytest.fixture(scope="module")
def seal_text_detection_predictor():
return SealTextDetection()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "seal.png",
],
)
def test_predict(seal_text_detection_predictor, image_path):
result = seal_text_detection_predictor.predict(str(image_path))
check_simple_inference_result(result)
assert result[0].keys() == {
"input_path",
"page_index",
"input_img",
"dt_polys",
"dt_scores",
}
@pytest.mark.parametrize(
"params",
[
{"limit_side_len": 640, "limit_type": "min"},
{"thresh": 0.5},
{"box_thresh": 0.3},
{"unclip_ratio": 3.0},
],
)
def test_predict_params(
monkeypatch,
seal_text_detection_predictor,
params,
):
check_wrapper_simple_inference_param_forwarding(
monkeypatch,
seal_text_detection_predictor,
"paddlex_predictor",
"dummy_path",
params,
)

View File

@@ -0,0 +1,48 @@
import pytest
from paddleocr import TableCellsDetection
from ..testing_utils import (
TEST_DATA_DIR,
check_simple_inference_result,
check_wrapper_simple_inference_param_forwarding,
)
from .object_detection_common import check_result_item_keys
@pytest.fixture(scope="module")
def table_cells_detection_predictor():
return TableCellsDetection()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "table.jpg",
],
)
def test_predict(table_cells_detection_predictor, image_path):
result = table_cells_detection_predictor.predict(str(image_path))
check_simple_inference_result(result)
check_result_item_keys(result[0])
@pytest.mark.parametrize(
"params",
[
{"img_size": 640},
{"threshold": 0.5},
],
)
def test_predict_params(
monkeypatch,
table_cells_detection_predictor,
params,
):
check_wrapper_simple_inference_param_forwarding(
monkeypatch,
table_cells_detection_predictor,
"paddlex_predictor",
"dummy_path",
params,
)

View File

@@ -0,0 +1,23 @@
import pytest
from paddleocr import TableClassification
from ..testing_utils import TEST_DATA_DIR, check_simple_inference_result
from .image_classification_common import check_result_item_keys
@pytest.fixture(scope="module")
def table_classification_predictor():
return TableClassification()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "table.jpg",
],
)
def test_predict(table_classification_predictor, image_path):
result = table_classification_predictor.predict(str(image_path))
check_simple_inference_result(result)
check_result_item_keys(result[0])

View File

@@ -0,0 +1,53 @@
import pytest
from paddleocr import TableStructureRecognition
from ..testing_utils import (
TEST_DATA_DIR,
check_simple_inference_result,
check_wrapper_simple_inference_param_forwarding,
)
@pytest.fixture(scope="module")
def table_structure_recognition_predictor():
return TableStructureRecognition()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "table.jpg",
],
)
def test_predict(table_structure_recognition_predictor, image_path):
result = table_structure_recognition_predictor.predict(str(image_path))
check_simple_inference_result(result)
assert result[0].keys() == {
"input_path",
"page_index",
"input_img",
"bbox",
"structure",
"structure_score",
}
@pytest.mark.parametrize(
"params",
[
{},
],
)
def test_predict_params(
monkeypatch,
table_structure_recognition_predictor,
params,
):
check_wrapper_simple_inference_param_forwarding(
monkeypatch,
table_structure_recognition_predictor,
"paddlex_predictor",
"dummy_path",
params,
)

View File

@@ -0,0 +1,55 @@
import pytest
from paddleocr import TextDetection
from ..testing_utils import (
TEST_DATA_DIR,
check_simple_inference_result,
check_wrapper_simple_inference_param_forwarding,
)
@pytest.fixture(scope="module")
def text_detection_predictor():
return TextDetection()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "table.jpg",
],
)
def test_predict(text_detection_predictor, image_path):
result = text_detection_predictor.predict(str(image_path))
check_simple_inference_result(result)
assert result[0].keys() == {
"input_path",
"page_index",
"input_img",
"dt_polys",
"dt_scores",
}
@pytest.mark.parametrize(
"params",
[
{"limit_side_len": 640, "limit_type": "min"},
{"thresh": 0.5},
{"box_thresh": 0.3},
{"unclip_ratio": 3.0},
],
)
def test_predict_params(
monkeypatch,
text_detection_predictor,
params,
):
check_wrapper_simple_inference_param_forwarding(
monkeypatch,
text_detection_predictor,
"paddlex_predictor",
"dummy_path",
params,
)

View File

@@ -0,0 +1,51 @@
import pytest
from paddleocr import TextImageUnwarping
from ..testing_utils import (
TEST_DATA_DIR,
check_simple_inference_result,
check_wrapper_simple_inference_param_forwarding,
)
@pytest.fixture(scope="module")
def text_image_unwarping_predictor():
return TextImageUnwarping()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "book.jpg",
],
)
def test_predict(text_image_unwarping_predictor, image_path):
result = text_image_unwarping_predictor.predict(str(image_path))
check_simple_inference_result(result)
assert result[0].keys() == {
"input_path",
"page_index",
"input_img",
"doctr_img",
}
@pytest.mark.parametrize(
"params",
[
{},
],
)
def test_predict_params(
monkeypatch,
text_image_unwarping_predictor,
params,
):
check_wrapper_simple_inference_param_forwarding(
monkeypatch,
text_image_unwarping_predictor,
"paddlex_predictor",
"dummy_path",
params,
)

View File

@@ -0,0 +1,29 @@
import pytest
from paddleocr import TextRecognition
from ..testing_utils import TEST_DATA_DIR, check_simple_inference_result
@pytest.fixture(scope="module")
def text_recognition_predictor():
return TextRecognition()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "textline.png",
],
)
def test_predict(text_recognition_predictor, image_path):
result = text_recognition_predictor.predict(str(image_path))
check_simple_inference_result(result)
assert result[0].keys() == {
"input_path",
"page_index",
"input_img",
"rec_text",
"rec_score",
"vis_font",
}

View File

@@ -0,0 +1,23 @@
import pytest
from paddleocr import TextLineOrientationClassification
from ..testing_utils import TEST_DATA_DIR, check_simple_inference_result
from .image_classification_common import check_result_item_keys
@pytest.fixture(scope="module")
def textline_orientation_classification_predictor():
return TextLineOrientationClassification()
@pytest.mark.parametrize(
"image_path",
[
TEST_DATA_DIR / "textline_rot180.jpg",
],
)
def test_predict(textline_orientation_classification_predictor, image_path):
result = textline_orientation_classification_predictor.predict(str(image_path))
check_simple_inference_result(result)
check_result_item_keys(result[0])