OnnxGraphBuilder
Helpers & Utilities · AiDotNet.Onnx
Thin facade over the vendored ONNX protobuf types that lets layer converters add
nodes, initializers, inputs, and outputs to a model graph without touching the
generated GraphProto directly.
One OnnxGraphBuilder is created per export. Layer converters call
AddNode, AddInitializer, AddInput,
AddOutput, and NextTensorName as needed; the final
Build assembles a ModelProto ready to write.
This class is intentionally minimal in this initial commit — layer converters landing in subsequent commits drive the API additions they need.
Constructors
| Constructor | Summary |
|---|---|
OnnxGraphBuilder(OnnxExportOptions options) |
Properties
| Property | Summary |
|---|---|
int OpsetVersion { get; } |
Opset version the resulting model targets. |
Methods
| Method | Summary |
|---|---|
ModelProto Build() |
Assembles the final ModelProto with producer metadata + opset declaration. |
NodeProto AddOp(string opType, string[] inputs, string[] outputs, string name) |
Adds an ONNX op node with named inputs and outputs and optional attributes. |
string AddFloatInitializer(string namePrefix, float[] data, int[] shape) |
Adds a float32 constant initializer with the given shape. |
string NextTensorName(string prefix) |
Reserves a unique tensor name with the given prefix. |
void AddFloatInput(string name, int[] shape) |
Declares a float32 graph input with the given (fixed or symbolic) shape. |
void AddFloatOutput(string name, int[] shape) |
Declares a float32 graph output. |
void AddInitializer(TensorProto initializer) |
Adds a constant initializer (e.g., a layer’s weight tensor). |
void AddInput(ValueInfoProto input) |
Adds a graph input (a tensor the model expects from the caller). |
void AddNode(NodeProto node) |
Adds a node to the graph. |
void AddOutput(ValueInfoProto output) |
Adds a graph output (a tensor the model produces). |
void WriteTo(Stream stream) |
Serializes the built ModelProto to a stream. |