4 from onnx
import helper, shape_inference, optimizer
5 from onnx
import numpy_helper
6 from onnx
import AttributeProto, TensorProto, GraphProto
9 X = helper.make_tensor_value_info(
'X', TensorProto.FLOAT, [1])
11 W_info = helper.make_tensor_value_info(
'W', TensorProto.FLOAT, [1,8])
12 W = np.ones((1,8)).astype(np.float32)
13 W = numpy_helper.from_array(W,
'W')
15 B_info = helper.make_tensor_value_info(
'B', TensorProto.FLOAT, [8])
16 B = np.ones((8)).astype(np.float32)
17 B = numpy_helper.from_array(B,
'B')
20 Z = helper.make_tensor_value_info(
'Z', TensorProto.FLOAT, [8])
22 matmul1 = helper.make_node(
28 bias1 = helper.make_node(
35 graph_def = helper.make_graph(
36 nodes=[matmul1, bias1],
37 name=
'dense_a_model',
38 inputs = [X, W_info, B_info],
43 model_def = helper.make_model(graph_def, producer_name=
'benchmarks')
45 onnx.checker.check_model(model_def)
46 model_def = shape_inference.infer_shapes(model_def)
47 onnx.checker.check_model(model_def)
48 model_def = optimizer.optimize(model_def)
49 onnx.checker.check_model(model_def)
51 onnx.save_model(model_def,
'04_dense_a.onnx')