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, 1, 32, 32])
11 W_info = helper.make_tensor_value_info(
'W', TensorProto.FLOAT, [5, 1, 3, 3])
12 W = np.array([[[[-1,-1,-1],[-1,8.1,-1],[-1,-1,-1]]],[[[0,-1,0],[-1,5,-1],[0,-1,0]]],[[[-2,-1,0],[-1,1,1],[0,1,2]]],[[[1,2,1],[0,0,0],[-1,-2,-1]]],[[[1,0,-1],[2,0,-2],[1,0,-1]]]]).astype(np.float32)
13 W = numpy_helper.from_array(W,
'W')
17 Y = helper.make_tensor_value_info(
'Y', TensorProto.FLOAT, [1, 5, 32, 32])
19 conv1 = helper.make_node(
30 graph_def = helper.make_graph(
38 model_def = helper.make_model(graph_def, producer_name=
'benchmarks')
40 onnx.checker.check_model(model_def)
41 model_def = shape_inference.infer_shapes(model_def)
42 onnx.checker.check_model(model_def)
43 model_def = optimizer.optimize(model_def)
44 onnx.checker.check_model(model_def)
46 onnx.save_model(model_def,
'e2_conv.onnx')