base.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. import inspect
  15. from ...utils.func_register import FuncRegister
  16. from ..utils.io import ImageReader, ImageWriter
  17. from .utils.mixin import JsonMixin, ImgMixin, StrMixin
  18. class BaseResult(dict, StrMixin, JsonMixin):
  19. def __init__(self, data):
  20. super().__init__(data)
  21. self._show_funcs = []
  22. StrMixin.__init__(self)
  23. JsonMixin.__init__(self)
  24. def save_all(self, save_path):
  25. for func in self._show_funcs:
  26. signature = inspect.signature(func)
  27. if "save_path" in signature.parameters:
  28. func(save_path=save_path)
  29. else:
  30. func()
  31. class CVResult(BaseResult, ImgMixin):
  32. def __init__(self, data):
  33. super().__init__(data)
  34. ImgMixin.__init__(self, "pillow")
  35. self._img_reader = ImageReader(backend="pillow")
  36. self._img_writer = ImageWriter(backend="pillow")