public static OnnxCSharpToProtoWrapper.ModelProto MakeModel(List <OnnxCSharpToProtoWrapper.NodeProto> nodes, string producerName, string name,
                                                                    string domain, string producerVersion, long modelVersion, int opSetVersion, List <ModelArgs> inputs,
                                                                    List <ModelArgs> outputs, List <ModelArgs> intermediateValues, List <OnnxCSharpToProtoWrapper.TensorProto> initializers)
        {
            Contracts.CheckValue(nodes, nameof(nodes));
            Contracts.CheckValue(inputs, nameof(inputs));
            Contracts.CheckValue(outputs, nameof(outputs));
            Contracts.CheckValue(intermediateValues, nameof(intermediateValues));
            Contracts.CheckValue(initializers, nameof(initializers));
            Contracts.CheckNonEmpty(producerName, nameof(producerName));
            Contracts.CheckNonEmpty(name, nameof(name));
            Contracts.CheckNonEmpty(domain, nameof(domain));
            Contracts.CheckNonEmpty(producerVersion, nameof(producerVersion));

            var model = new OnnxCSharpToProtoWrapper.ModelProto();

            model.Domain          = domain;
            model.ProducerName    = producerName;
            model.ProducerVersion = producerVersion;
            model.IrVersion       = (long)OnnxCSharpToProtoWrapper.Version.IrVersion;
            model.ModelVersion    = modelVersion;
            model.OpsetImport.Add(new OnnxCSharpToProtoWrapper.OperatorSetIdProto()
            {
                Domain = "ai.onnx.ml", Version = 2
            });
            model.OpsetImport.Add(new OnnxCSharpToProtoWrapper.OperatorSetIdProto()
            {
                Domain = "", Version = opSetVersion
            });
            model.Graph = new OnnxCSharpToProtoWrapper.GraphProto();
            var graph = model.Graph;

            graph.Node.Add(nodes);
            graph.Name = name;
            foreach (var arg in inputs)
            {
                var val = new OnnxCSharpToProtoWrapper.ValueInfoProto();
                graph.Input.Add(val);
                MakeValue(val, arg.Name, arg.DataType, arg.Dims, arg.DimParams);
            }

            foreach (var arg in outputs)
            {
                var val = new OnnxCSharpToProtoWrapper.ValueInfoProto();
                graph.Output.Add(val);
                MakeValue(val, arg.Name, arg.DataType, arg.Dims, arg.DimParams);
            }

            foreach (var arg in intermediateValues)
            {
                var val = new OnnxCSharpToProtoWrapper.ValueInfoProto();
                graph.ValueInfo.Add(val);
                MakeValue(val, arg.Name, arg.DataType, arg.Dims, arg.DimParams);
            }

            graph.Initializer.AddRange(initializers);

            return(model);
        }
        private static OnnxCSharpToProtoWrapper.ValueInfoProto MakeValue(OnnxCSharpToProtoWrapper.ValueInfoProto value, string name, OnnxCSharpToProtoWrapper.TensorProto.Types.DataType dataType,
                                                                         List <long> dims, List <bool> dimsParam)
        {
            Contracts.CheckValue(value, nameof(value));
            Contracts.CheckNonEmpty(name, nameof(name));

            value.Name = name;
            if (value.Type == null)
            {
                value.Type = new OnnxCSharpToProtoWrapper.TypeProto();
            }

            MakeType(value.Type, dataType, dims, dimsParam);
            return(value);
        }