Spaces:
Runtime error
Runtime error
File size: 1,145 Bytes
f518bf0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import importlib
from os import path as osp
from basicsr.utils import get_root_logger, scandir
# automatically scan and import model modules
# scan all the files under the 'models' folder and collect files ending with
# '_model.py'
model_folder = osp.dirname(osp.abspath(__file__))
model_filenames = [
osp.splitext(osp.basename(v))[0] for v in scandir(model_folder)
if v.endswith('_model.py')
]
# import all the model modules
_model_modules = [
importlib.import_module(f'basicsr.models.{file_name}')
for file_name in model_filenames
]
def create_model(opt):
"""Create model.
Args:
opt (dict): Configuration. It constains:
model_type (str): Model type.
"""
model_type = opt['model_type']
# dynamic instantiation
for module in _model_modules:
model_cls = getattr(module, model_type, None)
if model_cls is not None:
break
if model_cls is None:
raise ValueError(f'Model {model_type} is not found.')
model = model_cls(opt)
logger = get_root_logger()
logger.info(f'Model [{model.__class__.__name__}] is created.')
return model
|