@@ -555,3 +555,121 @@ def build_convtranspose_conv_residual_model():
555555 onnx .checker .check_model (model_inferred )
556556
557557 return model_inferred
558+
559+
560+ def build_conv_batchnorm_sig_mul_model ():
561+ # Define your model inputs and outputs
562+ input_names = ["input_0" ]
563+ output_names = ["output_0" ]
564+ input_shapes = [(6 , 48 , 64 , 176 )]
565+ output_shapes = [(6 , 48 , 64 , 176 )]
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 = "Relu" ,
580+ inputs = ["input_0" ],
581+ outputs = ["relu0_relu/Relu:0" ],
582+ name = "relu0_relu/Relu" ,
583+ ),
584+ helper .make_node (
585+ op_type = "Conv" ,
586+ inputs = ["relu0_relu/Relu:0" , "weights_1" ],
587+ outputs = ["conv1_conv/Conv2D:0" ],
588+ name = "conv1_conv/Conv2D" ,
589+ dilations = [1 , 1 ],
590+ group = 1 ,
591+ kernel_shape = [3 , 3 ],
592+ pads = [1 , 1 , 1 , 1 ],
593+ strides = [1 , 1 ],
594+ ),
595+ helper .make_node (
596+ op_type = "BatchNormalization" ,
597+ inputs = ["conv1_conv/Conv2D:0" , "bn1_scale" , "bn1_bias" , "bn1_mean" , "bn1_var" ],
598+ outputs = ["bn1_batchnorm/BatchNormalization:0" ],
599+ name = "bn1_batchnorm/BatchNormalization" ,
600+ ),
601+ helper .make_node (
602+ op_type = "Sigmoid" ,
603+ inputs = ["bn1_batchnorm/BatchNormalization:0" ],
604+ outputs = ["sig1_sigmoid/Sigmoid:0" ],
605+ name = "sig1_sigmoid/Sigmoid" ,
606+ ),
607+ helper .make_node (
608+ op_type = "Mul" ,
609+ inputs = ["sig1_sigmoid/Sigmoid:0" , "bn1_batchnorm/BatchNormalization:0" ],
610+ outputs = ["mul1_mul/Mul:0" ],
611+ name = "mul1_mul/Mul" ,
612+ ),
613+ helper .make_node (
614+ op_type = "Add" ,
615+ inputs = ["relu0_relu/Relu:0" , "mul1_mul/Mul:0" ],
616+ outputs = ["add1_add/Add:0" ],
617+ name = "add1_add/Add" ,
618+ ),
619+ helper .make_node (
620+ op_type = "Relu" ,
621+ inputs = ["add1_add/Add:0" ],
622+ outputs = ["output_0" ],
623+ name = "relu2_relu/Relu" ,
624+ ),
625+ ]
626+
627+ # Create the ONNX initializers
628+ initializers = [
629+ helper .make_tensor (
630+ name = "weights_1" ,
631+ data_type = onnx .TensorProto .FLOAT ,
632+ dims = (48 , 48 , 3 , 3 ),
633+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 48 * 48 * 3 * 3 ),
634+ ),
635+ helper .make_tensor (
636+ name = "bn1_scale" ,
637+ data_type = onnx .TensorProto .FLOAT ,
638+ dims = (48 ,),
639+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 48 ),
640+ ),
641+ helper .make_tensor (
642+ name = "bn1_bias" ,
643+ data_type = onnx .TensorProto .FLOAT ,
644+ dims = (48 ,),
645+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 48 ),
646+ ),
647+ helper .make_tensor (
648+ name = "bn1_mean" ,
649+ data_type = onnx .TensorProto .FLOAT ,
650+ dims = (48 ,),
651+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 48 ),
652+ ),
653+ helper .make_tensor (
654+ name = "bn1_var" ,
655+ data_type = onnx .TensorProto .FLOAT ,
656+ dims = (48 ,),
657+ vals = np .random .uniform (low = 0.5 , high = 1.0 , size = 48 ),
658+ ),
659+ ]
660+
661+ # Create the ONNX graph with the nodes and initializers
662+ graph = helper .make_graph (
663+ nodes , "conv_batchnorm_sig_mul" , inputs , outputs , initializer = initializers
664+ )
665+
666+ # Create the ONNX model
667+ model = helper .make_model (graph )
668+ model .opset_import [0 ].version = 13
669+ model .ir_version = 10
670+
671+ # Check the ONNX model
672+ model_inferred = onnx .shape_inference .infer_shapes (model )
673+ onnx .checker .check_model (model_inferred )
674+
675+ return model_inferred
0 commit comments