def test_case3(self): graph = build_graph(nodes, [('Op1', 'Op1_data'), ('Op1_data', 'result1')]) res_node_graph = Node(graph, 'Op1') res_node_graph['name'] = 'Op1_tensor' ResultRename().find_and_replace_pattern(graph) res_node = Node(graph, 'result1') self.assertTrue(res_node['name'] == 'Op1_tensor/sink_port_0')
def test_case4(self): graph = build_graph(nodes, [('Op1', 'Op1_data'), ('Op1_data', 'result1'), ('Op1_data', 'Op2'), ('Op2', 'Op2_data'), ('Op2_data', 'result2')]) ResultRename().find_and_replace_pattern(graph) res1_node = Node(graph, 'result1') res2_node = Node(graph, 'result2') self.assertTrue(res1_node['name'] == 'Op1_tensor') self.assertTrue(res2_node['name'] == 'Op2_tensor')
def test_case2(self): graph = build_graph(nodes, []) graph_ref = build_graph(nodes, []) ResultRename().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result1', check_op_attrs=True) self.assertTrue(flag, resp)
def prepare_emit_ir(graph: Graph, data_type: str, output_dir: str, output_model_name: str, mean_data: [list, None] = None, input_names: list = None, meta_info: dict = None): if input_names is None: input_names = [] if meta_info is None: meta_info = {} graph.strict_mode = False # convert Parameter data types convert_data_type.convert_parameters_data_type(graph, data_type) # convert blobs (usually weights and biases) for sub_graph in [graph] + collect_sub_graphs(graph): convert_data_type.convert_blobs(sub_graph, data_type) # restore data type for specific inputs/outputs of specific ops to the data types required by nGraph for_graph_and_each_sub_graph_recursively(graph, convert_inputs_of_specific_ops) for_graph_and_each_sub_graph_recursively(graph, OpVersioning().find_and_replace_pattern) # do not run the type inference in sub-graphs. It will be called automatically as part of the type inference of # the TensorIterator nodes type_infer(graph) RemoveUselessConvert().find_and_replace_pattern(graph) ResultRename().find_and_replace_pattern(graph) for sub_graph in [graph] + collect_sub_graphs(graph): op_order, data_order = determined_sort(get_sorted_outputs(sub_graph)) mapping = {v: u for u, v in enumerate(op_order)} mapping.update({v: u for u, v in enumerate(data_order, start=len(sub_graph))}) relabel_nodes_inplace_safe(sub_graph, mapping) port_renumber(sub_graph) tensor_names.propagate_op_name_to_tensor(graph) bin_file = os.path.join(output_dir, '{}.bin'.format(output_model_name)) serialize_constants(graph, bin_file) mean_offset = None mean_size = None if mean_data: mean_offset, mean_size = serialize_mean_image(bin_file, mean_data=mean_data) generate_ie_ir(graph=graph, file_name=os.path.join(output_dir, '{}.xml'.format(output_model_name)), input_names=input_names, mean_offset=mean_offset, mean_size=mean_size, meta_info=meta_info) tensor_names.output_tensor_names_map(graph, os.path.join(output_dir, '{}.mapping'.format(output_model_name)))
def test_case1(self): graph = build_graph(nodes, [('Op1', 'Op1_data'), ('Op1_data', 'result')]) graph_ref = build_graph(nodes, [('Op1', 'Op1_data'), ('Op1_data', 'result')]) res_node = Node(graph_ref, 'result') res_node['name'] = 'Op1_tensor' ResultRename().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) self.assertTrue(flag, resp)