__init__.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. from . import version
  22. from .inference import create_pipeline, create_predictor
  23. from .model import create_model
  24. from .modules import build_dataset_checker, build_evaluator, build_trainer
  25. def _initialize():
  26. from . import repo_apis, repo_manager
  27. from .utils import flags
  28. from .utils.logging import setup_logging
  29. __DIR__ = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
  30. repo_manager.set_parent_dirs(
  31. os.path.join(__DIR__, "repo_manager", "repos"), repo_apis
  32. )
  33. setup_logging()
  34. if flags.EAGER_INITIALIZATION:
  35. repo_manager.initialize()
  36. __version__ = version.get_pdx_version()
  37. _initialize()
  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. )