test_pp_structurev3.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import pytest
  2. from paddleocr import PPStructureV3
  3. from ..testing_utils import (
  4. TEST_DATA_DIR,
  5. check_simple_inference_result,
  6. check_wrapper_simple_inference_param_forwarding,
  7. )
  8. @pytest.fixture(scope="module")
  9. def pp_structurev3_pipeline():
  10. return PPStructureV3()
  11. @pytest.mark.resource_intensive
  12. @pytest.mark.parametrize(
  13. "image_path",
  14. [
  15. TEST_DATA_DIR / "doc_with_formula.png",
  16. ],
  17. )
  18. def test_predict(pp_structurev3_pipeline, image_path):
  19. result = pp_structurev3_pipeline.predict(str(image_path))
  20. check_simple_inference_result(result)
  21. res = result[0]
  22. overall_ocr_res = res["overall_ocr_res"]
  23. assert len(overall_ocr_res["dt_polys"]) > 0
  24. assert len(overall_ocr_res["rec_texts"]) > 0
  25. assert len(overall_ocr_res["rec_polys"]) > 0
  26. assert len(overall_ocr_res["rec_boxes"]) > 0
  27. @pytest.mark.parametrize(
  28. "params",
  29. [
  30. {"use_doc_orientation_classify": False},
  31. {"use_doc_unwarping": False},
  32. {"use_table_recognition": False},
  33. {"use_formula_recognition": False},
  34. {"layout_threshold": 0.88},
  35. {"layout_threshold": [0.45, 0.4]},
  36. {"layout_threshold": {0: 0.45, 2: 0.48, 7: 0.4}},
  37. {"layout_nms": False},
  38. {"layout_unclip_ratio": 1.1},
  39. {"layout_unclip_ratio": [1.2, 1.5]},
  40. {"layout_unclip_ratio": {0: 1.2, 2: 1.5, 7: 1.8}},
  41. {"layout_merge_bboxes_mode": "large"},
  42. {"layout_merge_bboxes_mode": {0: "large", 2: "small", 7: "union"}},
  43. {"text_det_limit_side_len": 640, "text_det_limit_type": "min"},
  44. {"text_det_thresh": 0.5},
  45. {"text_det_box_thresh": 0.3},
  46. {"text_det_unclip_ratio": 3.0},
  47. {"text_rec_score_thresh": 0.5},
  48. ],
  49. )
  50. def test_predict_params(
  51. monkeypatch,
  52. pp_structurev3_pipeline,
  53. params,
  54. ):
  55. check_wrapper_simple_inference_param_forwarding(
  56. monkeypatch,
  57. pp_structurev3_pipeline,
  58. "paddlex_pipeline",
  59. "dummy_path",
  60. params,
  61. )
  62. # TODO: Test constructor and other methods