-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ci for paddleocr test * fix flake8 error * fix paddlepaddle deps * add dep * fix * move flake8 to pre-commit * update ut * fix bug * fix bug set paddlepaddle==2.5 * fix bug * fix bug * fix bug * update test * remove lscpu
- Loading branch information
Showing
14 changed files
with
184 additions
and
18 deletions.
There are no files selected for viewing
10 changes: 6 additions & 4 deletions
10
.github/workflows/pre-commit.yml → .github/workflows/codestyle.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: PaddleOCR PR Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
branches: ["main", "release/*"] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test-pr: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
pip install "paddlepaddle==2.5" requests | ||
pip install -e . | ||
- name: Test with pytest | ||
run: | | ||
pytest tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from typing import Any | ||
|
||
import pytest | ||
from paddleocr import PaddleOCR, PPStructure | ||
|
||
|
||
# Test image paths | ||
IMAGE_PATHS_OCR = ["./doc/imgs_en/254.jpg", "./doc/imgs_en/img_10.jpg"] | ||
IMAGE_PATHS_STRUCTURE = [ | ||
"./ppstructure/docs/table/layout.jpg", | ||
"./ppstructure/docs/table/1.png", | ||
] | ||
|
||
|
||
@pytest.fixture(params=["en", "ch"]) | ||
def ocr_engine(request: Any) -> PaddleOCR: | ||
""" | ||
Initialize PaddleOCR engine with different languages. | ||
Args: | ||
request: pytest fixture request object. | ||
Returns: | ||
An instance of PaddleOCR. | ||
""" | ||
return PaddleOCR(lang=request.param) | ||
|
||
|
||
def test_ocr_initialization(ocr_engine: PaddleOCR) -> None: | ||
""" | ||
Test PaddleOCR initialization. | ||
Args: | ||
ocr_engine: An instance of PaddleOCR. | ||
""" | ||
assert ocr_engine is not None | ||
|
||
|
||
@pytest.mark.parametrize("image_path", IMAGE_PATHS_OCR) | ||
def test_ocr_function(ocr_engine: PaddleOCR, image_path: str) -> None: | ||
""" | ||
Test PaddleOCR OCR functionality with different images. | ||
Args: | ||
ocr_engine: An instance of PaddleOCR. | ||
image_path: Path to the image to be processed. | ||
""" | ||
result = ocr_engine.ocr(image_path) | ||
assert result is not None | ||
assert isinstance(result, list) | ||
|
||
|
||
@pytest.mark.parametrize("image_path", IMAGE_PATHS_OCR) | ||
def test_ocr_det_only(ocr_engine: PaddleOCR, image_path: str) -> None: | ||
""" | ||
Test PaddleOCR OCR functionality with detection only. | ||
Args: | ||
ocr_engine: An instance of PaddleOCR. | ||
image_path: Path to the image to be processed. | ||
""" | ||
result = ocr_engine.ocr(image_path, det=True, rec=False) | ||
assert result is not None | ||
assert isinstance(result, list) | ||
|
||
|
||
@pytest.mark.parametrize("image_path", IMAGE_PATHS_OCR) | ||
def test_ocr_rec_only(ocr_engine: PaddleOCR, image_path: str) -> None: | ||
""" | ||
Test PaddleOCR OCR functionality with recognition only. | ||
Args: | ||
ocr_engine: An instance of PaddleOCR. | ||
image_path: Path to the image to be processed. | ||
""" | ||
result = ocr_engine.ocr(image_path, det=False, rec=True) | ||
assert result is not None | ||
assert isinstance(result, list) | ||
|
||
|
||
@pytest.fixture(params=["en", "ch"]) | ||
def structure_engine(request: Any) -> PPStructure: | ||
""" | ||
Initialize PPStructure engine with different languages. | ||
Args: | ||
request: pytest fixture request object. | ||
Returns: | ||
An instance of PPStructure. | ||
""" | ||
return PPStructure(lang=request.param) | ||
|
||
|
||
def test_structure_initialization(structure_engine: PPStructure) -> None: | ||
""" | ||
Test PPStructure initialization. | ||
Args: | ||
structure_engine: An instance of PPStructure. | ||
""" | ||
assert structure_engine is not None | ||
|
||
|
||
@pytest.mark.parametrize("image_path", IMAGE_PATHS_STRUCTURE) | ||
def test_structure_function(structure_engine: PPStructure, image_path: str) -> None: | ||
""" | ||
Test PPStructure structure analysis functionality with different images. | ||
Args: | ||
structure_engine: An instance of PPStructure. | ||
image_path: Path to the image to be processed. | ||
""" | ||
result = structure_engine(image_path) | ||
assert result is not None | ||
assert isinstance(result, list) |