test_instance_segmentation.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 InstanceSegResult
  15. from tests.models.base import BaseTestPredictor
  16. from tests.testing_utils.cv import compare_det_results
  17. from paddlex_hpi.models import InstanceSegPredictor
  18. MODEL_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/instance_seg_model.zip"
  19. INPUT_DATA_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/instance_seg_input.jpg"
  20. EXPECTED_RESULT_URL = "https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/deploy/paddlex_hpi/tests/models/instance_seg_result.json"
  21. class TestInstanceSegPredictor(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 InstanceSegPredictor
  34. def _check_result(self, result, expected_result):
  35. assert isinstance(result, InstanceSegResult)
  36. assert set(result) == set(expected_result)
  37. # TODO: Check masks
  38. compare_det_results(
  39. [obj["coordinate"] for obj in result["boxes"]],
  40. [obj["coordinate"] for obj in expected_result["boxes"]],
  41. labels1=[obj["cls_id"] for obj in result["boxes"]],
  42. labels2=[obj["cls_id"] for obj in expected_result["boxes"]],
  43. scores1=[obj["score"] for obj in result["boxes"]],
  44. scores2=[obj["score"] for obj in expected_result["boxes"]],
  45. )