@@ -555,3 +555,128 @@ def build_convtranspose_conv_residual_model():
555555 onnx .checker .check_model (model_inferred )
556556
557557 return model_inferred
558+
559+
560+ def build_conv_act_pool_model ():
561+ # Define your model inputs and outputs
562+ input_names = ["input_0" ]
563+ output_names = ["output_0" ]
564+ input_shapes = [(32 , 64 , 256 , 256 )]
565+ output_shapes = [(32 , 128 , 128 , 128 )]
566+
567+ inputs = [
568+ helper .make_tensor_value_info (input_name , onnx .TensorProto .FLOAT , input_shape )
569+ for input_name , input_shape in zip (input_names , input_shapes )
570+ ]
571+ outputs = [
572+ helper .make_tensor_value_info (output_name , onnx .TensorProto .FLOAT , output_shape )
573+ for output_name , output_shape in zip (output_names , output_shapes )
574+ ]
575+
576+ # Create the ONNX graph with the nodes
577+ nodes = [
578+ helper .make_node (
579+ op_type = "Conv" ,
580+ inputs = ["input_0" , "weights_1" , "bias_1" ],
581+ outputs = ["conv1_conv/Conv2D:0" ],
582+ name = "conv1_conv/Conv2D" ,
583+ dilations = [1 , 1 ],
584+ group = 1 ,
585+ kernel_shape = [3 , 3 ],
586+ pads = [0 , 0 , 0 , 0 ],
587+ strides = [1 , 1 ],
588+ ),
589+ helper .make_node (
590+ op_type = "BatchNormalization" ,
591+ inputs = ["conv1_conv/Conv2D:0" , "bn1_scale" , "bn1_bias" , "bn1_mean" , "bn1_var" ],
592+ outputs = ["bn1_batchnorm/BatchNormalization:0" ],
593+ name = "bn1_batchnorm/BatchNormalization" ,
594+ ),
595+ helper .make_node (
596+ op_type = "Relu" ,
597+ inputs = ["bn1_batchnorm/BatchNormalization:0" ],
598+ outputs = ["relu1_relu/Relu:0" ],
599+ name = "relu1_relu/Relu" ,
600+ ),
601+ helper .make_node (
602+ op_type = "MaxPool" ,
603+ inputs = ["relu1_relu/Relu:0" ],
604+ outputs = ["maxpool1_maxpool/MaxPool2D:0" ],
605+ name = "maxpool1_maxpool/MaxPool2D" ,
606+ ceil_mode = False ,
607+ kernel_shape = [3 , 3 ],
608+ pads = [0 , 0 , 0 , 0 ],
609+ strides = [2 , 2 ],
610+ ),
611+ helper .make_node (
612+ op_type = "Conv" ,
613+ inputs = ["maxpool1_maxpool/MaxPool2D:0" , "weights_2" ],
614+ outputs = ["output_0" ],
615+ name = "conv2_conv/Conv2D" ,
616+ dilations = [1 , 1 ],
617+ group = 1 ,
618+ kernel_shape = [3 , 3 ],
619+ pads = [0 , 0 , 0 , 0 ],
620+ strides = [1 , 1 ],
621+ ),
622+ ]
623+
624+ # Create the ONNX initializers
625+ initializers = [
626+ helper .make_tensor (
627+ name = "weights_1" ,
628+ data_type = onnx .TensorProto .FLOAT ,
629+ dims = (128 , 64 , 3 , 3 ),
630+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 128 * 64 * 3 * 3 ),
631+ ),
632+ helper .make_tensor (
633+ name = "bias_1" ,
634+ data_type = onnx .TensorProto .FLOAT ,
635+ dims = (128 ,),
636+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 128 ),
637+ ),
638+ helper .make_tensor (
639+ name = "bn1_scale" ,
640+ data_type = onnx .TensorProto .FLOAT ,
641+ dims = (128 ,),
642+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 128 ),
643+ ),
644+ helper .make_tensor (
645+ name = "bn1_bias" ,
646+ data_type = onnx .TensorProto .FLOAT ,
647+ dims = (128 ,),
648+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 128 ),
649+ ),
650+ helper .make_tensor (
651+ name = "bn1_mean" ,
652+ data_type = onnx .TensorProto .FLOAT ,
653+ dims = (128 ,),
654+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 128 ),
655+ ),
656+ helper .make_tensor (
657+ name = "bn1_var" ,
658+ data_type = onnx .TensorProto .FLOAT ,
659+ dims = (128 ,),
660+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 128 ),
661+ ),
662+ helper .make_tensor (
663+ name = "weights_2" ,
664+ data_type = onnx .TensorProto .FLOAT ,
665+ dims = (128 , 128 , 3 , 3 ),
666+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 128 * 128 * 3 * 3 ),
667+ ),
668+ ]
669+
670+ # Create the ONNX graph with the nodes and initializers
671+ graph = helper .make_graph (nodes , "conv_act_pool" , inputs , outputs , initializer = initializers )
672+
673+ # Create the ONNX model
674+ model = helper .make_model (graph )
675+ model .opset_import [0 ].version = 13
676+ model .ir_version = 10
677+
678+ # Check the ONNX model
679+ model_inferred = onnx .shape_inference .infer_shapes (model )
680+ onnx .checker .check_model (model_inferred )
681+
682+ return model_inferred
0 commit comments