if node_proto.output is None: node_proto.output = [] output_types = output_arr.types type_attr = onnx.helper.make_attribute( output_arr.name + '-types', [ str(data_type).replace('tensor(', '').replace(')', '') for data_type in output_types ]) node_proto.attribute.append(type_attr) node_proto.output.append(output_arr.name) return node_proto nodes = [ create_node_from_schema(schema) for schema in sorted(schemas, key=lambda s: s.name) ] with open('onnx-op-defs.pb', 'wb') as f: graph_proto = GraphProto() graph_proto.node.extend(nodes) f.write(graph_proto.SerializeToString()) # for node in nodes: # message_to_string = text_format.MessageToString(node, as_utf8=True) # node_2 = load_node(message_to_string) # f.write(message_to_string + '----f\n') # with open('onnx.pbtxt','r') as f: # nodes = [load_node(node_str) for node_str in f.read().split('----f\n')] # print(nodes)
def _write_onnx(onnx_graph: onnx.GraphProto, out: Path) -> None: with open(out, "wb") as fp: fp.write(onnx_graph.SerializeToString())