Pklett commited on
Commit
90f88b7
·
1 Parent(s): 043b23f
Files changed (1) hide show
  1. utils.py +17 -0
utils.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .utils import *
2
+
3
+ import importlib
4
+
5
+
6
+ def instantiate_from_config(config):
7
+ if not "target" in config:
8
+ raise KeyError("Expected key `target` to instantiate.")
9
+ return get_obj_from_str(config["target"])(**config.get("params", dict()))
10
+
11
+
12
+ def get_obj_from_str(string, reload=False):
13
+ module, cls = string.rsplit(".", 1)
14
+ if reload:
15
+ module_imp = importlib.import_module(module)
16
+ importlib.reload(module_imp)
17
+ return getattr(importlib.import_module(module, package=None), cls)