pipeline.py 2.0 KB

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