Exemplo n.º 1
0
 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')
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
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,
                    use_temporary_path=False, used_by_ir_reader=False):
    if input_names is None:
        input_names = []
    if meta_info is None:
        meta_info = {}
    graph.strict_mode = False

    # temporary disable new FP16 generation
    # if not used_by_ir_reader:
    if True:
        # 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)

    for_graph_and_each_sub_graph_recursively(graph, RemoveUselessConvert().find_and_replace_pattern)

    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)

    ir_path_suffix = "_tmp" if use_temporary_path else ""

    bin_file = os.path.join(output_dir, '{}{}.bin'.format(output_model_name, ir_path_suffix))
    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, ir_path_suffix)),
                   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, ir_path_suffix)))
Exemplo n.º 4
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')