Skip to content

add ci for paddleocr test #12062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: pre-commit
name: PaddleOCR Code Style Check

on:
pull_request:
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PaddleOCR PR Tests

on:
push:
pull_request:
branches: ["main", "release/*"]

permissions:
contents: read

jobs:
build:
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 flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install paddlepaddle requests
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 ppocr/ --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 ppocr/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest tests/
10 changes: 5 additions & 5 deletions ppocr/data/imaug/label_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,11 @@ def __call__(self, data):
return data

def xyxyxyxy2xywh(self, boxes):
new_bboxes = np.zeros([len(bboxes), 4])
new_bboxes[:, 0] = bboxes[:, 0::2].min() # x1
new_bboxes[:, 1] = bboxes[:, 1::2].min() # y1
new_bboxes[:, 2] = bboxes[:, 0::2].max() - new_bboxes[:, 0] # w
new_bboxes[:, 3] = bboxes[:, 1::2].max() - new_bboxes[:, 1] # h
new_bboxes = np.zeros([len(boxes), 4])
new_bboxes[:, 0] = boxes[:, 0::2].min() # x1
new_bboxes[:, 1] = boxes[:, 1::2].min() # y1
new_bboxes[:, 2] = boxes[:, 0::2].max() - new_bboxes[:, 0] # w
new_bboxes[:, 3] = boxes[:, 1::2].max() - new_bboxes[:, 1] # h
return new_bboxes

def xyxy2xywh(self, bboxes):
Expand Down
4 changes: 3 additions & 1 deletion ppocr/losses/distillation_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,9 @@ def forward(self, predicts, batch):
loss = super().forward(out1, out2, ctc_label)
if isinstance(loss, dict):
for key in loss:
loss_dict["{}_{}_{}".format(self.name, model_name, idx)] = loss[key]
loss_dict[
"{}_{}_{}".format(self.name, self.model_name_pairs, idx)
] = loss[key]
else:
loss_dict["{}_{}".format(self.name, idx)] = loss
return loss_dict
2 changes: 1 addition & 1 deletion ppocr/metrics/vqa_token_re_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np
import paddle

__all__ = ["KIEMetric"]
__all__ = ["VQAReTokenMetric"]


class VQAReTokenMetric(object):
Expand Down
2 changes: 1 addition & 1 deletion ppocr/metrics/vqa_token_ser_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np
import paddle

__all__ = ["KIEMetric"]
__all__ = ["VQASerTokenMetric"]


class VQASerTokenMetric(object):
Expand Down
2 changes: 1 addition & 1 deletion ppocr/modeling/backbones/rec_efficientb3_pren.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import paddle.nn as nn
import paddle.nn.functional as F

__all__ = ["EfficientNetb3"]
__all__ = ["EfficientNetb3_PREN"]

GlobalParams = collections.namedtuple(
"GlobalParams",
Expand Down
2 changes: 1 addition & 1 deletion ppocr/modeling/heads/rec_aster_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def sample(self, x):
# Decoder
state = paddle.zeros([1, batch_size, self.sDim])

predicted_ids, predicted_scores = [], []
predicted_ids, predicted_scores, predicted = [], [], None
for i in range(self.max_len_labels):
if i == 0:
y_prev = paddle.full(shape=[batch_size], fill_value=self.num_classes)
Expand Down
5 changes: 4 additions & 1 deletion ppocr/utils/loggers/wandb_logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os
from .base_logger import BaseLogger
from ppocr.utils.logging import get_logger

logger = get_logger()


class WandbLogger(BaseLogger):
Expand All @@ -11,7 +14,7 @@ def __init__(
entity=None,
save_dir=None,
config=None,
**kwargs
**kwargs,
):
try:
import wandb
Expand Down
37 changes: 37 additions & 0 deletions tests/test_paddleocr_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest
import cv2
from paddleocr import PaddleOCR


@pytest.fixture
def ocr():
return PaddleOCR(lang="en")


@pytest.fixture
def img():
return cv2.imread("doc/imgs/1.jpg")


def test_ocr_with_detection_and_recognition(ocr, img):
result = ocr.ocr(img, det=True, rec=True)
assert result is not None
assert isinstance(result, list)


def test_ocr_with_detection_only(ocr, img):
result = ocr.ocr(img, det=True, rec=False)
assert result is not None
assert isinstance(result, list)


def test_ocr_with_recognition_only(ocr, img):
result = ocr.ocr(img, det=False, rec=True)
assert result is not None
assert isinstance(result, list)


def test_ocr_without_detection_and_recognition(ocr, img):
result = ocr.ocr(img, det=False, rec=False)
assert result is not None
assert isinstance(result, list)