INNER CODE UNIT · Python
_ensure_arch_modules_imported
piddnad/DDColor · basicsr/archs/__init__.py:14
def _ensure_arch_modules_imported():
"""Lazy import arch modules for registry.
In upstream BasicSR, importing `basicsr.archs` scans and imports all `*_arch.py`
modules eagerly to populate the registry. That adds import overhead and may
pull in extra dependencies in inference-only scenarios.
Here we make it lazy: only scan/import when `build_network` is actually called.
"""
global _ARCHS_IMPORTED
if _ARCHS_IMPORTED:
return
arch_folder = osp.dirname(osp.abspath(__file__))
arch_filenames = []
for name in os.listdir(arch_folder):
if name.endswith("_arch.py"):
arch_filenames.append(osp.splitext(name)[0])
for file_name in arch_filenames:
importlib.import_module(f'basicsr.archs.{file_name}')