test_pp_doctranslation.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import pytest
  2. from paddleocr import PPDocTranslation
  3. from ..testing_utils import TEST_DATA_DIR
  4. @pytest.fixture(scope="module")
  5. def pp_doctranslation_pipeline():
  6. return PPDocTranslation()
  7. @pytest.mark.parametrize(
  8. "image_path",
  9. [
  10. TEST_DATA_DIR / "book.jpg",
  11. ],
  12. )
  13. def test_visual_predict(pp_doctranslation_pipeline, image_path):
  14. result = pp_doctranslation_pipeline.visual_predict(str(image_path))
  15. assert result is not None
  16. assert isinstance(result, list)
  17. assert len(result) == 1
  18. res = result[0]
  19. assert isinstance(res, dict)
  20. assert res.keys() == {"layout_parsing_result"}
  21. assert isinstance(res["layout_parsing_result"], dict)
  22. @pytest.mark.parametrize(
  23. "params",
  24. [
  25. {"use_doc_orientation_classify": False},
  26. {"use_doc_unwarping": False},
  27. {"use_table_recognition": False},
  28. {"use_formula_recognition": False},
  29. {"layout_threshold": 0.88},
  30. {"layout_threshold": [0.45, 0.4]},
  31. {"layout_threshold": {0: 0.45, 2: 0.48, 7: 0.4}},
  32. {"layout_nms": False},
  33. {"layout_unclip_ratio": 1.1},
  34. {"layout_unclip_ratio": [1.2, 1.5]},
  35. {"layout_unclip_ratio": {0: 1.2, 2: 1.5, 7: 1.8}},
  36. {"layout_merge_bboxes_mode": "large"},
  37. {"layout_merge_bboxes_mode": {0: "large", 2: "small", 7: "union"}},
  38. {"text_det_limit_side_len": 640, "text_det_limit_type": "min"},
  39. {"text_det_thresh": 0.5},
  40. {"text_det_box_thresh": 0.3},
  41. {"text_det_unclip_ratio": 3.0},
  42. {"text_rec_score_thresh": 0.5},
  43. ],
  44. )
  45. def test_visual_predict_params(
  46. monkeypatch,
  47. pp_doctranslation_pipeline,
  48. params,
  49. ):
  50. def _dummy_visual_predict(input, **params):
  51. yield {"layout_parsing_result": params}
  52. monkeypatch.setattr(
  53. pp_doctranslation_pipeline.paddlex_pipeline,
  54. "visual_predict",
  55. _dummy_visual_predict,
  56. )
  57. result = pp_doctranslation_pipeline.visual_predict(
  58. input,
  59. **params,
  60. )
  61. assert isinstance(result, list)
  62. assert len(result) == 1
  63. res = result[0]
  64. res = res["layout_parsing_result"]
  65. for k, v in params.items():
  66. assert res[k] == v
  67. # TODO: Test constructor and other methods