PandA-2024.02
15_onnx_build.py
Go to the documentation of this file.
1 import numpy as np
2 
3 import onnx
4 from onnx import helper, shape_inference, optimizer
5 from onnx import numpy_helper
6 from onnx import AttributeProto, TensorProto, GraphProto
7 
8 # Create graph input X
9 X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 8])
10 
11 # Create graph output Z
12 Z = helper.make_tensor_value_info('Z', TensorProto.FLOAT, [1, 8])
13 
14 tanh1 = helper.make_node(
15  'Tanh', # name
16  ['X'], # inputs
17  ['Y'], # outputs
18  )
19 
20 exp2 = helper.make_node(
21  'Exp',
22  ['Y'],
23  ['V'],
24  )
25 
26 relu3 = helper.make_node(
27  'Relu',
28  ['V'],
29  ['VV']
30  )
31 
32 sigmoid4 = helper.make_node(
33  'Sigmoid',
34  ['VV'],
35  ['Z'],
36  )
37 
38 
39 graph_def = helper.make_graph(
40  nodes=[tanh1, exp2, relu3, sigmoid4], # graph nodes
41  name= 'thxprlsg_model', # graph name
42  inputs = [X], # graph inputs
43  outputs = [Z], # graph outputs
44  )
45 
46 model_def = helper.make_model(graph_def, producer_name='benchmarks')
47 
48 onnx.checker.check_model(model_def)
49 model_def = shape_inference.infer_shapes(model_def)
50 onnx.checker.check_model(model_def)
51 model_def = optimizer.optimize(model_def)
52 onnx.checker.check_model(model_def)
53 
54 onnx.save_model(model_def, '15_thxprlsg.onnx')

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13