コード例 #1
0
def prepare_emit_ir(graph: nx.MultiDiGraph, data_type: str, output_dir: str, output_model_name: str,
                    mean_data: [list, None] = None, input_names: list = [], meta_info: dict = dict()):

    for sub_graph in [graph] + collect_sub_graphs(graph):
        create_const_nodes(sub_graph, start_data_nodes_are_not_allowed=(sub_graph == 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)
        convert_data_type.convert(sub_graph, data_type)

    tensor_names.propagate_op_name_to_tensor(graph)
    weights = np.array([])
    bin_file = os.path.join(output_dir, '{}.bin'.format(output_model_name))
    if(data_type == "FP16"):
        weights = serialize_constants(weights,graph,data_type=np.float16)
    elif(data_type == "FP32"):
        weights = serialize_constants(weights,graph,data_type=np.float32)

    mean_offset = None
    mean_size = None
    if mean_data:
        mean_offset, mean_size = serialize_mean_image(bin_file, mean_data=mean_data)

    xml_string = 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)))
    return weights, xml_string
コード例 #2
0
 def test_get_sorted_outputs_fine_situation(self):
     nodes = {'A': {'type': 'Identity', 'kind': 'op'},
              'B': {'type': 'Identity', 'kind': 'op'},
              'C': {'type': 'Identity', 'kind': 'op'},
              'D': {'type': 'Identity', 'kind': 'op'},
              'E': {'type': 'Identity', 'kind': 'op'},
              'F': {'type': 'Identity', 'kind': 'op'},
              'G': {'type': 'Identity', 'kind': 'op'},
              'H': {'type': 'Identity', 'kind': 'op'},
              'Ad': {'value': None, 'kind': 'data'},
              'Bd': {'value': None, 'kind': 'data'},
              'Cd': {'value': None, 'kind': 'data', 'fw_tensor_debug_info': [('C', 0)]},
              'Dd': {'value': None, 'kind': 'data'},
              'Ed': {'value': None, 'kind': 'data', 'fw_tensor_debug_info': [('E', 0)]},
              'Fd': {'value': None, 'kind': 'data', 'fw_tensor_debug_info': [('F', 0)]},
              'Gd': {'value': None, 'kind': 'data', 'fw_tensor_debug_info': [('G', 0)]},
              'Hd': {'value': None, 'kind': 'data', 'fw_tensor_debug_info': [('H', 0)]}
              }
     edges = [
         ('A', 'Ad', {'out': 0}),
         ('Ad', 'B', {'in': 0}),
         ('B', 'Bd', {'out': 0}),
         ('Bd', 'C', {'in': 0}),
         ('C', 'Cd', {'out': 0}),
         ('Cd', 'D', {'in': 0}),
         ('D', 'Dd', {'out': 0}),
         ('Dd', 'E', {'in': 0}),
         ('E', 'Ed', {'out': 0}),
         ('Cd', 'F', {'in': 0}),
         ('F', 'Fd', {'out': 0}),
         ('Fd', 'G', {'in': 0}),
         ('G', 'Gd', {'out': 0}),
         ('Cd', 'H', {'in': 0}),
         ('H', 'Hd', {'out': 0})
     ]
     graph = build_graph_with_edge_attrs(nodes, edges)
     self.assertListEqual([node.id for node in get_sorted_outputs(graph)], ['Ed', 'Gd', 'Hd'])