__init__.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 / "configs/pipelines" / f"{pipeline_name}.yaml"
  47. ).resolve()
  48. if not Path(pipeline_path).exists():
  49. return None
  50. return pipeline_path
  51. def load_pipeline_config(pipeline_name: str) -> Dict[str, Any]:
  52. if not Path(pipeline_name).exists():
  53. pipeline_path = get_pipeline_path(pipeline_name)
  54. if pipeline_path is None:
  55. raise Exception(
  56. f"The pipeline ({pipeline_name}) does not exist! Please use a pipeline name or a config file path!"
  57. )
  58. else:
  59. pipeline_path = pipeline_name
  60. config = parse_config(pipeline_path)
  61. return config
  62. def create_pipeline(
  63. pipeline: str,
  64. device=None,
  65. pp_option=None,
  66. use_hpip: bool = False,
  67. hpi_params: Optional[Dict[str, Any]] = None,
  68. *args,
  69. **kwargs,
  70. ) -> BasePipeline:
  71. """build model evaluater
  72. Args:
  73. pipeline (str): the pipeline name, that is name of pipeline class
  74. Returns:
  75. BasePipeline: the pipeline, which is subclass of BasePipeline.
  76. """
  77. pipeline_name = pipeline
  78. config = load_pipeline_config(pipeline_name)
  79. assert pipeline_name == config["pipeline_name"]
  80. pipeline = BasePipeline.get(pipeline_name)(
  81. config=config,
  82. device=device,
  83. pp_option=pp_option,
  84. use_hpip=use_hpip,
  85. hpi_params=hpi_params)
  86. return pipeline