Helper to return a function object by name. func_name must identify a function in this module or the path to a function relative to the base 'modeling' module.
(func_name)
| 5 | |
| 6 | |
| 7 | def get_func(func_name): |
| 8 | """Helper to return a function object by name. func_name must identify a |
| 9 | function in this module or the path to a function relative to the base |
| 10 | 'modeling' module. |
| 11 | """ |
| 12 | if func_name == '': |
| 13 | return None |
| 14 | try: |
| 15 | parts = func_name.split('.') |
| 16 | # Refers to a function in this module |
| 17 | if len(parts) == 1: |
| 18 | return globals()[parts[0]] |
| 19 | # Otherwise, assume we're referencing a module under modeling |
| 20 | module_name = 'lib.' + '.'.join(parts[:-1]) |
| 21 | module = importlib.import_module(module_name) |
| 22 | return getattr(module, parts[-1]) |
| 23 | except Exception: |
| 24 | print('Failed to f1ind function: %s', func_name) |
| 25 | raise |
| 26 | |
| 27 | def load_ckpt(args, depth_model, shift_model, focal_model): |
| 28 | """ |