__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 pathlib import Path
  15. from typing import Any, Dict, Optional
  16. from ...utils.config import parse_config
  17. from .base import BasePipeline
  18. from .single_model_pipeline import SingleModelPipeline
  19. from .ocr import OCRPipeline
  20. from .table_recognition import TableRecPipeline
  21. def create_pipeline(
  22. pipeline: str,
  23. use_hpip: bool = False,
  24. hpi_params: Optional[Dict[str, Any]] = None,
  25. *args,
  26. **kwargs,
  27. ) -> BasePipeline:
  28. """build model evaluater
  29. Args:
  30. pipeline (str): the pipeline name, that is name of pipeline class
  31. Returns:
  32. BasePipeline: the pipeline, which is subclass of BasePipeline.
  33. """
  34. if not Path(pipeline).exists():
  35. # XXX: using dict class to handle all pipeline configs
  36. pipeline = (
  37. Path(__file__).parent.parent.parent / "pipelines" / f"{pipeline}.yaml"
  38. )
  39. if not Path(pipeline).exists():
  40. raise Exception(f"The pipeline don't exist! ({pipeline})")
  41. config = parse_config(pipeline)
  42. pipeline_name = config["Global"]["pipeline_name"]
  43. predictor_kwargs = {"use_hpip": use_hpip}
  44. if hpi_params is not None:
  45. predictor_kwargs["hpi_params"] = hpi_params
  46. pipeline = BasePipeline.get(pipeline_name)(
  47. predictor_kwargs=predictor_kwargs, *args, **config["Pipeline"], **kwargs
  48. )
  49. return pipeline