__init__.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 .base import BasePipeline
  17. from ...utils.config import parse_config
  18. # from .single_model_pipeline import (
  19. # _SingleModelPipeline,
  20. # ImageClassification,
  21. # ObjectDetection,
  22. # InstanceSegmentation,
  23. # SemanticSegmentation,
  24. # TSFc,
  25. # TSAd,
  26. # TSCls,
  27. # MultiLableImageClas,
  28. # SmallObjDet,
  29. # AnomalyDetection,
  30. # )
  31. # from .ocr import OCRPipeline
  32. # from .formula_recognition import FormulaRecognitionPipeline
  33. # from .table_recognition import TableRecPipeline
  34. # from .face_recognition import FaceRecPipeline
  35. # from .seal_recognition import SealOCRPipeline
  36. # from .ppchatocrv3 import PPChatOCRPipeline
  37. # from .layout_parsing import LayoutParsingPipeline
  38. # from .pp_shitu_v2 import ShiTuV2Pipeline
  39. # from .attribute_recognition import AttributeRecPipeline
  40. from .ocr import OCRPipeline
  41. from .doc_preprocessor import DocPreprocessorPipeline
  42. from .layout_parsing import LayoutParsingPipeline
  43. from .pp_chatocrv3_doc import PP_ChatOCRv3_doc_Pipeline
  44. def get_pipeline_path(pipeline_name):
  45. pipeline_path = (
  46. Path(__file__).parent.parent.parent
  47. / "configs/pipelines"
  48. / f"{pipeline_name}.yaml"
  49. ).resolve()
  50. if not Path(pipeline_path).exists():
  51. return None
  52. return pipeline_path
  53. def load_pipeline_config(pipeline_name: str) -> Dict[str, Any]:
  54. if not Path(pipeline_name).exists():
  55. pipeline_path = get_pipeline_path(pipeline_name)
  56. if pipeline_path is None:
  57. raise Exception(
  58. f"The pipeline ({pipeline_name}) does not exist! Please use a pipeline name or a config file path!"
  59. )
  60. else:
  61. pipeline_path = pipeline_name
  62. config = parse_config(pipeline_path)
  63. return config
  64. def create_pipeline(
  65. pipeline: str,
  66. device=None,
  67. pp_option=None,
  68. use_hpip: bool = False,
  69. hpi_params: Optional[Dict[str, Any]] = None,
  70. *args,
  71. **kwargs,
  72. ) -> BasePipeline:
  73. """build model evaluater
  74. Args:
  75. pipeline (str): the pipeline name, that is name of pipeline class
  76. Returns:
  77. BasePipeline: the pipeline, which is subclass of BasePipeline.
  78. """
  79. pipeline_name = pipeline
  80. config = load_pipeline_config(pipeline_name)
  81. assert pipeline_name == config["pipeline_name"]
  82. pipeline = BasePipeline.get(pipeline_name)(
  83. config=config,
  84. device=device,
  85. pp_option=pp_option,
  86. use_hpip=use_hpip,
  87. hpi_params=hpi_params,
  88. )
  89. return pipeline