test_table_recognition.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from paddlex_hpi.models import TablePredictor
  15. from tests.models.base import BaseTestPredictor
  16. from tests.testing_utils.cv import compare_det_results
  17. from paddlex.inference.results import TableRecResult
  18. MODEL_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/table_model.zip"
  19. INPUT_DATA_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/table_input.jpg"
  20. EXPECTED_RESULT_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/table_result.json"
  21. class TestTablePredictor(BaseTestPredictor):
  22. @property
  23. def model_url(self):
  24. return MODEL_URL
  25. @property
  26. def input_data_url(self):
  27. return INPUT_DATA_URL
  28. @property
  29. def expected_result_url(self):
  30. return EXPECTED_RESULT_URL
  31. @property
  32. def predictor_cls(self):
  33. return TablePredictor
  34. def _check_result(self, result, expected_result):
  35. def _unflatten_poly(poly):
  36. return [
  37. [poly[0], poly[1]],
  38. [poly[2], poly[3]],
  39. [poly[4], poly[5]],
  40. [poly[6], poly[7]],
  41. ]
  42. assert isinstance(result, TableRecResult)
  43. assert "input_img" in result
  44. result.pop("input_img")
  45. assert set(result) == set(expected_result)
  46. compare_det_results(
  47. [_unflatten_poly(poly) for poly in result["bbox"]],
  48. [_unflatten_poly(poly) for poly in expected_result["bbox"]],
  49. labels1=result["structure"],
  50. labels2=expected_result["structure"],
  51. )