ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onnx-dump Namespace Reference

Functions

 _data_type_str (data_type)
 
 _get_attribute_value (attr)
 
 _gather_value_infos (onnx_model)
 
 _type_format (type)
 
 _dump_header (onnx_model)
 
 _dump_operators (onnx_model)
 
 _dump_initializers (onnx_model)
 
 _dump_nodes (onnx_model)
 
 _dump_inputoutputs (onnx_model)
 
 _dump_graph (onnx_model)
 
 _help_exit (cmd_name)
 
 main ()
 

Function Documentation

◆ _data_type_str()

onnx-dump._data_type_str (   data_type)
protected

Definition at line 26 of file onnx-dump.py.

26def _data_type_str(data_type):
27 return TensorProto.DataType.Name(data_type)
28
29

Referenced by _dump_initializers(), _dump_inputoutputs(), _get_attribute_value(), and _type_format().

◆ _dump_graph()

onnx-dump._dump_graph (   onnx_model)
protected

Definition at line 157 of file onnx-dump.py.

157def _dump_graph(onnx_model):
158 _dump_header(onnx_model)
159 _dump_operators(onnx_model)
160 _dump_initializers(onnx_model)
161 _dump_nodes(onnx_model)
162 _dump_inputoutputs(onnx_model)
163
164

References _dump_header(), _dump_initializers(), _dump_inputoutputs(), _dump_nodes(), and _dump_operators().

Referenced by main().

◆ _dump_header()

onnx-dump._dump_header (   onnx_model)
protected

Definition at line 68 of file onnx-dump.py.

68def _dump_header(onnx_model):
69 print("[General] -----------------------------")
70 print("IR version =", onnx_model.ir_version)
71 print("Producer =", onnx_model.producer_name, onnx_model.producer_version)
72 print("")
73
74

Referenced by _dump_graph().

◆ _dump_initializers()

onnx-dump._dump_initializers (   onnx_model)
protected

Definition at line 95 of file onnx-dump.py.

95def _dump_initializers(onnx_model):
96 print("[Initializers] ------------------------")
97 for initializer in onnx_model.graph.initializer:
98 init_name = '"{}"'.format(initializer.name)
99 dtstr = _data_type_str(initializer.data_type)
100 print('{:<15} {} {}'.format(init_name, dtstr, initializer.dims))
101
102 print("")
103
104

References _data_type_str().

Referenced by _dump_graph().

◆ _dump_inputoutputs()

onnx-dump._dump_inputoutputs (   onnx_model)
protected

Definition at line 138 of file onnx-dump.py.

138def _dump_inputoutputs(onnx_model):
139 print("[Graph Input/Output]-------------------")
140 for mod_input in onnx_model.graph.input:
141 io_name = '"{}"'.format(mod_input.name)
142 dtstr = _data_type_str(mod_input.type.tensor_type.elem_type)
143 shape = mod_input.type.tensor_type.shape
144 input_shape = [dim.dim_value for dim in shape.dim]
145 print(' I: {:<15} {} {}'.format(io_name, dtstr, input_shape))
146
147 for mod_output in onnx_model.graph.output:
148 io_name = '"{}"'.format(mod_output.name)
149 dtstr = _data_type_str(mod_output.type.tensor_type.elem_type)
150 shape = mod_output.type.tensor_type.shape
151 output_shape = [dim.dim_value for dim in shape.dim]
152 print(' O: {:<15} {} {}'.format(io_name, dtstr, output_shape))
153
154 print("")
155
156

References _data_type_str().

Referenced by _dump_graph().

◆ _dump_nodes()

onnx-dump._dump_nodes (   onnx_model)
protected

Definition at line 105 of file onnx-dump.py.

105def _dump_nodes(onnx_model):
106 print("[Nodes] -------------------------------")
107
108 vis = _gather_value_infos(onnx_model)
109
110 for node in onnx_model.graph.node:
111 print('{0}("{1}")'.format(node.op_type, node.name))
112
113 attribute = ''
114 for attr in node.attribute:
115 if attribute != '':
116 attribute += ', '
117 attribute += "{}: {}".format(attr.name, _get_attribute_value(attr))
118
119 if attribute != '':
120 print(' A {0}'.format(attribute))
121
122 for inp in node.input:
123 inp_vi_str = ''
124 if inp in vis:
125 inp_vi = vis[inp]
126 inp_vi_str = _type_format(inp_vi)
127 print(' I "{0}" {1}'.format(inp, inp_vi_str))
128 for out in node.output:
129 out_vi_str = ''
130 if out in vis:
131 out_vi = vis[out]
132 out_vi_str = _type_format(out_vi)
133 print(' O "{0}" {1}'.format(out, out_vi_str))
134
135 print("")
136
137

References _gather_value_infos(), _get_attribute_value(), and _type_format().

Referenced by _dump_graph().

◆ _dump_operators()

onnx-dump._dump_operators (   onnx_model)
protected

Definition at line 75 of file onnx-dump.py.

75def _dump_operators(onnx_model):
76 opcodes_dict = dict()
77 for node in onnx_model.graph.node:
78 if node.op_type in opcodes_dict:
79 opcodes_dict[node.op_type] = opcodes_dict[node.op_type] + 1
80 else:
81 opcodes_dict[node.op_type] = 1
82
83 print("[Operators] ---------------------------")
84 total_nodes = 0
85 for opcode_key in opcodes_dict:
86 print("{:>5} {}".format(opcodes_dict[opcode_key], opcode_key))
87 total_nodes = total_nodes + opcodes_dict[opcode_key]
88
89 print("----- -----")
90 print("{:>5} {}".format(total_nodes, 'Total'))
91
92 print("")
93
94

Referenced by _dump_graph().

◆ _gather_value_infos()

onnx-dump._gather_value_infos (   onnx_model)
protected

Definition at line 46 of file onnx-dump.py.

46def _gather_value_infos(onnx_model):
47 vis = dict()
48
49 for mod_input in onnx_model.graph.input:
50 vis[mod_input.name] = mod_input.type
51
52 for mod_output in onnx_model.graph.output:
53 vis[mod_output.name] = mod_output.type
54
55 for vi in onnx_model.graph.value_info:
56 vis[vi.name] = vi.type
57
58 return vis
59
60

Referenced by _dump_nodes().

◆ _get_attribute_value()

onnx-dump._get_attribute_value (   attr)
protected

Definition at line 30 of file onnx-dump.py.

30def _get_attribute_value(attr):
31 if attr.type == AttributeProto.TENSOR:
32 return "{}, {}".format(_data_type_str(attr.t.data_type),
33 numpy_helper.to_array(attr.t))
34 if attr.type == AttributeProto.GRAPH:
35 # TODO revise when graph node is available
36 return "<graph>"
37 if attr.type == AttributeProto.TENSORS:
38 # TODO revise to see contents
39 return "<tensors>..."
40 if attr.type == AttributeProto.GRAPHS:
41 # TODO revise when graph node is available
42 return "<graphs>..."
43 return helper.get_attribute_value(attr)
44
45

References _data_type_str().

Referenced by _dump_nodes().

◆ _help_exit()

onnx-dump._help_exit (   cmd_name)
protected

Definition at line 165 of file onnx-dump.py.

165def _help_exit(cmd_name):
166 print('Dump ONNX model file Graph')
167 print('Usage: {0} [onnx_path]'.format(cmd_name))
168 print('')
169 exit()
170
171

Referenced by main().

◆ _type_format()

onnx-dump._type_format (   type)
protected

Definition at line 61 of file onnx-dump.py.

61def _type_format(type):
62 dtstr = _data_type_str(type.tensor_type.elem_type)
63 shape = type.tensor_type.shape
64 shape_ar = [dim.dim_value for dim in shape.dim]
65 return '{} {}'.format(dtstr, shape_ar)
66
67

References _data_type_str().

Referenced by _dump_nodes().

◆ main()

onnx-dump.main ( void  )

Definition at line 172 of file onnx-dump.py.

172def main():
173 if len(sys.argv) < 2:
174 _help_exit(os.path.basename(sys.argv[0]))
175
176 onnx.checker.check_model(sys.argv[1])
177 onnx_model = onnx.load(sys.argv[1])
178
179 _dump_graph(onnx_model)
180
181
int main(void)

References _dump_graph(), _help_exit(), and main().

Referenced by main().