Spaces:
Configuration error
Configuration error
File size: 984 Bytes
5602c9a |
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 |
"""
Copy from stable diffusion
"""
import importlib
def instantiate_from_config(config:dict, **args_from_code):
"""Util funciton to decompose differenct modules using config
Args:
config (dict): with key of "target" and "params", better from yaml
static
args_from_code: additional con
Returns:
a validation/training pipeline, a module
"""
if not "target" in config:
if config == '__is_first_stage__':
return None
elif config == "__is_unconditional__":
return None
raise KeyError("Expected key `target` to instantiate.")
return get_obj_from_str(config["target"])(**config.get("params", dict()), **args_from_code)
def get_obj_from_str(string, reload=False):
module, cls = string.rsplit(".", 1)
if reload:
module_imp = importlib.import_module(module)
importlib.reload(module_imp)
return getattr(importlib.import_module(module, package=None), cls)
|