def collect_extenders(path: str): """ A function to registrate all MO IR Reader extenders :param path: Path to Model Optimizer folder :return: """ import_by_path(os.path.join(path, 'mo', 'utils', 'ir_reader', 'extenders'), ['mo', 'utils', 'ir_reader', 'extenders'], 'openvino.tools.') update_registration(classes=[Extender], enabled_transforms=[], disabled_transforms=[])
def load_dir(framework: str, path: str, get_front_classes: callable): """ Assuming the following sub-directory structure for path: front/ <framework>/ <other_files>.py <other_directories>/ <other_files>.py ops/ <ops_files>.py middle/ <other_files>.py back/ <other_files>.py This function loads modules in the following order: 1. ops/<ops_files>.py 2. front/<other_files>.py 3. front/<framework>/<other_files>.py 4. middle/<other_files>.py 5. back/<other_files>.py Handlers loaded later override earlier registered handlers for an op. 1, 2, 3 can concur for the same op, but 4 registers a transformation pass and it shouldn't conflict with any stuff loaded by 1, 2 or 3. It doesn't load files from front/<other_directories> """ log.info("Importing extensions from: {}".format(path)) root_dir, ext = os.path.split(path) sys.path.insert(0, root_dir) enabled_transforms, disabled_transforms = get_enabled_and_disabled_transforms( ) front_classes = get_front_classes() internal_dirs = { ('ops', ): [Op], ('analysis', ): [AnalyzeAction], ('load', framework): [Loader], ('front', ): front_classes, ('front', framework): front_classes, ('front', framework, 'extractors'): front_classes, ('middle', ): [MiddleReplacementPattern], ('back', ): [BackReplacementPattern] } prefix = 'openvino.tools.' if ext == 'mo' else '' for p in internal_dirs.keys(): import_by_path(os.path.join(path, *p), [ext, *p], prefix) update_registration(internal_dirs[p], enabled_transforms, disabled_transforms) sys.path.remove(root_dir)
def collect_ops(path: str): """ A function to registrate all MO ops :param path: Path to Model Optimizer folder :return: """ import_by_path(os.path.join(path, 'mo', 'ops'), ['mo', 'ops'], 'openvino.tools.') update_registration(classes=[ Op, Activation, Elementwise, UnaryElementwise, LogicalElementwise, EmbeddingBagBase, ReduceOp, Scatter, ScatterNDBase, FFTBase ], enabled_transforms=[], disabled_transforms=[])