coreml-community/ControlNet-v1-1-Annotators-cpu
15
1# Copyright (c) Facebook, Inc. and its affiliates.2import importlib.abc3import importlib.util4from pathlib import Path5 6__all__ = []7 8_PROJECTS = {9 "point_rend": "PointRend",10 "deeplab": "DeepLab",11 "panoptic_deeplab": "Panoptic-DeepLab",12}13_PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent / "projects"14 15if _PROJECT_ROOT.is_dir():16 # This is true only for in-place installation (pip install -e, setup.py develop),17 # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/23018 19 class _D2ProjectsFinder(importlib.abc.MetaPathFinder):20 def find_spec(self, name, path, target=None):21 if not name.startswith("detectron2.projects."):22 return23 project_name = name.split(".")[-1]24 project_dir = _PROJECTS.get(project_name)25 if not project_dir:26 return27 target_file = _PROJECT_ROOT / f"{project_dir}/{project_name}/__init__.py"28 if not target_file.is_file():29 return30 return importlib.util.spec_from_file_location(name, target_file)31 32 import sys33 34 sys.meta_path.append(_D2ProjectsFinder())35 