__init__.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  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 importlib import import_module
  15. from pathlib import Path
  16. from typing import Any, Dict, Optional, Union
  17. from ...utils import errors
  18. from ..utils.hpi import HPIConfig
  19. from ..utils.official_models import official_models
  20. # from .table_recognition import TablePredictor
  21. # from .general_recognition import ShiTuRecPredictor
  22. from .anomaly_detection import UadPredictor
  23. from .base import BasePredictor
  24. from .doc_vlm import DocVLMPredictor
  25. from .face_feature import FaceFeaturePredictor
  26. from .formula_recognition import FormulaRecPredictor
  27. from .image_classification import ClasPredictor
  28. from .image_feature import ImageFeaturePredictor
  29. from .image_multilabel_classification import MLClasPredictor
  30. from .image_unwarping import WarpPredictor
  31. from .instance_segmentation import InstanceSegPredictor
  32. from .keypoint_detection import KptPredictor
  33. from .m_3d_bev_detection import BEVDet3DPredictor
  34. # from .face_recognition import FaceRecPredictor
  35. from .multilingual_speech_recognition import WhisperPredictor
  36. from .object_detection import DetPredictor
  37. from .open_vocabulary_detection import OVDetPredictor
  38. from .open_vocabulary_segmentation import OVSegPredictor
  39. from .semantic_segmentation import SegPredictor
  40. from .table_structure_recognition import TablePredictor
  41. from .text_detection import TextDetPredictor
  42. from .text_recognition import TextRecPredictor
  43. from .ts_anomaly_detection import TSAdPredictor
  44. from .ts_classification import TSClsPredictor
  45. from .ts_forecasting import TSFcPredictor
  46. from .video_classification import VideoClasPredictor
  47. from .video_detection import VideoDetPredictor
  48. def create_predictor(
  49. model_name: str,
  50. model_dir: Optional[str] = None,
  51. device=None,
  52. pp_option=None,
  53. use_hpip: bool = False,
  54. hpi_config: Optional[Union[Dict[str, Any], HPIConfig]] = None,
  55. *args,
  56. **kwargs,
  57. ) -> BasePredictor:
  58. if model_dir is None:
  59. assert (
  60. model_name in official_models
  61. ), f"The model ({model_name}) is not supported! Please using directory of local model files or model name supported by PaddleX!"
  62. model_dir = official_models[model_name]
  63. else:
  64. assert Path(model_dir).exists(), f"{model_dir} is not exists!"
  65. model_dir = Path(model_dir)
  66. config = BasePredictor.load_config(model_dir)
  67. assert (
  68. model_name == config["Global"]["model_name"]
  69. ), f"Model name mismatch,please input the correct model dir."
  70. return BasePredictor.get(model_name)(
  71. model_dir=model_dir,
  72. config=config,
  73. device=device,
  74. pp_option=pp_option,
  75. use_hpip=use_hpip,
  76. hpi_config=hpi_config,
  77. *args,
  78. **kwargs,
  79. )