__init__.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. import os
  15. import sys
  16. _SPECIAL_MODS = ["paddle", "paddle_custom_device", "ultra_infer"]
  17. _loaded_special_mods = []
  18. for mod in _SPECIAL_MODS:
  19. if mod in sys.modules:
  20. _loaded_special_mods.append(mod)
  21. def _initialize():
  22. from . import repo_apis, repo_manager
  23. from .utils import flags
  24. from .utils.logging import setup_logging
  25. __DIR__ = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
  26. repo_manager.set_parent_dirs(
  27. os.path.join(__DIR__, "repo_manager", "repos"), repo_apis
  28. )
  29. setup_logging()
  30. if flags.EAGER_INITIALIZATION:
  31. repo_manager.initialize()
  32. _initialize()
  33. from . import version
  34. __version__ = version.get_pdx_version()
  35. from .inference import create_pipeline, create_predictor
  36. from .model import create_model
  37. from .modules import build_dataset_checker, build_evaluator, build_trainer
  38. for mod in _SPECIAL_MODS:
  39. if mod in sys.modules and mod not in _loaded_special_mods:
  40. raise AssertionError(
  41. f"`{mod}` is unexpectedly loaded. Please contact the PaddleX team to report this issue."
  42. )