Team Ai
Apppublic

radames/Text2Human-API

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
__init__.py43 linesDownload Raw Back to models
1import glob2import importlib3import logging4import os.path as osp5 6# automatically scan and import model modules7# scan all the files under the 'models' folder and collect files ending with8# '_model.py'9model_folder = osp.dirname(osp.abspath(__file__))10model_filenames = [11    osp.splitext(osp.basename(v))[0]12    for v in glob.glob(f'{model_folder}/*_model.py')13]14# import all the model modules15_model_modules = [16    importlib.import_module(f'models.{file_name}')17    for file_name in model_filenames18]19 20 21def create_model(opt):22    """Create model.23 24    Args:25        opt (dict): Configuration. It constains:26            model_type (str): Model type.27    """28    model_type = opt['model_type']29 30    # dynamically instantiation31    for module in _model_modules:32        model_cls = getattr(module, model_type, None)33        if model_cls is not None:34            break35    if model_cls is None:36        raise ValueError(f'Model {model_type} is not found.')37 38    model = model_cls(opt)39 40    logger = logging.getLogger('base')41    logger.info(f'Model [{model.__class__.__name__}] is created.')42    return model43