pipeline.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 abc import ABC, abstractmethod
  15. from ...utils.misc import AutoRegisterABCMetaClass
  16. def build_pipeline(
  17. pipeline_name: str,
  18. model_list: list,
  19. output: str,
  20. device: str, ) -> "BasePipeline":
  21. """build model evaluater
  22. Args:
  23. pipeline_name (str): the pipeline name, that is name of pipeline class
  24. Returns:
  25. BasePipeline: the pipeline, which is subclass of BasePipeline.
  26. """
  27. pipeline = BasePipeline.get(pipeline_name)(output=output, device=device)
  28. pipeline.update_model_name(model_list)
  29. pipeline.load_model()
  30. return pipeline
  31. class BasePipeline(ABC, metaclass=AutoRegisterABCMetaClass):
  32. """Base Pipeline
  33. """
  34. __is_base = True
  35. def __init__(self):
  36. super().__init__()
  37. @abstractmethod
  38. def load_model(self):
  39. """load model predictor
  40. """
  41. raise NotImplementedError
  42. @abstractmethod
  43. def update_model_name(self, model_list: list) -> dict:
  44. """update model name and re
  45. Args:
  46. model_list (list): list of model name.
  47. """
  48. raise NotImplementedError
  49. @abstractmethod
  50. def get_input_keys(self):
  51. """get dict keys of input argument input
  52. """
  53. raise NotImplementedError