def get_func(func_name): """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 = bytes2string(func_name) if func_name == '': return None new_func_name = name_compat.get_new_name(func_name) if new_func_name != func_name: logger.warn( 'Remapping old function name: {} -> {}'. format(func_name, new_func_name) ) func_name = new_func_name try: parts = func_name.split('.') # Refers to a function in this module if len(parts) == 1: return globals()[parts[0]] # Otherwise, assume we're referencing a module under modeling module_name = 'detectron.modeling.' + '.'.join(parts[:-1]) module = importlib.import_module(module_name) return getattr(module, parts[-1]) except Exception: logger.error('Failed to find function: {}'.format(func_name)) raise
def get_func(func_name): """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. """ if func_name == '': return None new_func_name = name_compat.get_new_name(func_name) if new_func_name != func_name: logger.warn( 'Remapping old function name: {} -> {}'. format(func_name, new_func_name) ) func_name = new_func_name try: parts = func_name.split('.') # Refers to a function in this module if len(parts) == 1: return globals()[parts[0]] # Otherwise, assume we're referencing a module under modeling module_name = 'detectron.modeling.' + '.'.join(parts[:-1]) module = importlib.import_module(module_name) return getattr(module, parts[-1]) except Exception: logger.error('Failed to find function: {}'.format(func_name)) raise