test_general_recognition.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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.inference.results import BaseResult
  15. from tests.models.base import BaseTestPredictor
  16. from paddlex_hpi.models import ShiTuRecPredictor
  17. MODEL_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/shitu_rec_model.zip"
  18. INPUT_DATA_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/shitu_rec_input.jpg"
  19. EXPECTED_RESULT_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/shitu_rec_result.json"
  20. class TestShiTuRecPredictor(BaseTestPredictor):
  21. @property
  22. def model_url(self):
  23. return MODEL_URL
  24. @property
  25. def input_data_url(self):
  26. return INPUT_DATA_URL
  27. @property
  28. def expected_result_url(self):
  29. return EXPECTED_RESULT_URL
  30. @property
  31. def predictor_cls(self):
  32. return ShiTuRecPredictor
  33. def _check_result(self, result, expected_result):
  34. assert isinstance(result, BaseResult)
  35. assert set(result) == set(expected_result)
  36. expected_result = expected_result["rec_feature"]
  37. result = result["rec_feature"].tolist()
  38. assert sum([abs(x - y) for x, y in zip(result, expected_result)]) < 0.001 * len(
  39. result
  40. )