A graph declares the type of each input and output, and optionally of the values
inside it, with ValueInfoProto messages. A type is a tensor of an element
type and shape, or a sequence, map, optional value, sparse tensor or opaque type built
from others. The last three messages on this page, SequenceProto, MapProto and
OptionalProto, hold such values themselves; a model rarely contains them, but they are
part of the same schema.
0A 01 78 12 0F 0A 0D 08 01 12 09 0A 02 08 01 0A 03 12 01 4E
x, type a FLOAT tensor of shape [1, N]; the explorer shows it as x: FLOAT [1, "N"]| Bytes | Meaning |
|---|---|
0A 01 78 | ValueInfoProto name: x. |
12 0F | type, a TypeProto of 15 bytes. |
0A 0D | TypeProto tensor_type, 13 bytes. |
08 01 | TypeProto.Tensor elem_type: 1, FLOAT. |
12 09 | shape, a TensorShapeProto of 9 bytes. |
0A 02 08 01 | A dim with dim_value 1. |
0A 03 12 01 4E | A dim with dim_param N. |
ValueInfoProto
A named value and its type: a graph input, output or intermediate value.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | name | string | LEN | The value’s name, as nodes use it. |
| 2 | type | TypeProto | LEN | Its type and shape. |
| 3 | doc_string | string | LEN | Documentation. |
| 4 | metadata_props | repeated StringStringEntryProto | LEN, one per entry | Named metadata (IR 10). |
TypeProto
A type. Fields 1, 4, 5, 7, 8 and 9 form a oneof: exactly one kind is set.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | tensor_type | TypeProto.Tensor | LEN | A tensor: element type and shape. |
| 4 | sequence_type | TypeProto.Sequence | LEN | A sequence of one element type. |
| 5 | map_type | TypeProto.Map | LEN | A map from integers or strings to a type. |
| 9 | optional_type | TypeProto.Optional | LEN | A value that may be absent (IR 8). |
| 8 | sparse_tensor_type | TypeProto.SparseTensor | LEN | A sparse tensor (IR 8). |
| 7 | opaque_type | TypeProto.Opaque | LEN | An opaque type, named by domain and name. Part of ONNX-ML until IR 14, which allows it everywhere. |
| 6 | denotation | string | LEN | A standard meaning for the whole type, such as IMAGE. |
TypeProto.Tensor
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | elem_type | int32 | VARINT | The element type, a data type. |
| 2 | shape | TensorShapeProto | LEN | The shape, if known. Absent means any shape. |
TypeProto.Sequence
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | elem_type | TypeProto | LEN | The type of each element. |
TypeProto.Map
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | key_type | int32 | VARINT | The key type: an integer data type or STRING. |
| 2 | value_type | TypeProto | LEN | The value type. |
TypeProto.Optional
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | elem_type | TypeProto | LEN | The type of the value, when present. |
TypeProto.SparseTensor
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | elem_type | int32 | VARINT | The element type. |
| 2 | shape | TensorShapeProto | LEN | The shape of the dense tensor. |
TypeProto.Opaque
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | domain | string | LEN | The domain; the model’s own when missing. |
| 2 | name | string | LEN | The type’s name. |
TensorShapeProto
A shape: a list of dimensions, outermost first. No dimensions is a scalar.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | dim | repeated Dimension | LEN, one per dimension | The dimensions. |
TensorShapeProto.Dimension
One dimension: a number, or a name for a size not known in advance, such as the batch size. Fields 1 and 2 form a oneof; with neither the size is unknown.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | dim_value | int64 | VARINT | The size. |
| 2 | dim_param | string | LEN | A symbolic size, such as N or batch; dimensions with the same name have the same size. |
| 3 | denotation | string | LEN | A standard meaning, such as DATA_BATCH or DATA_CHANNEL. |
SequenceProto
A sequence of values of one kind, from onnx-data.proto. As a file of its
own it is the ONNX sequence or optional value
format.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | name | string | LEN | The value’s name. |
| 2 | elem_type | int32 | VARINT | What the elements are: UNDEFINED 0, TENSOR 1, SPARSE_TENSOR 2, SEQUENCE 3, MAP 4, OPTIONAL 5. |
| 3 | tensor_values | repeated TensorProto | LEN, one per element | Elements, when TENSOR. |
| 4 | sparse_tensor_values | repeated SparseTensorProto | LEN, one per element | Elements, when SPARSE_TENSOR. |
| 5 | sequence_values | repeated SequenceProto | LEN, one per element | Elements, when SEQUENCE. |
| 6 | map_values | repeated MapProto | LEN, one per element | Elements, when MAP. |
| 7 | optional_values | repeated OptionalProto | LEN, one per element | Elements, when OPTIONAL. |
MapProto
A map: keys of one integer type or strings, and the values as a sequence of the same length.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | name | string | LEN | The value’s name. |
| 2 | key_type | int32 | VARINT | The key type: an integer data type or STRING. |
| 3 | keys | repeated int64 | VARINT per key, or packed LEN | Integer keys. |
| 4 | string_keys | repeated bytes | LEN, one per key | String keys. |
| 5 | values | SequenceProto | LEN | The values, in the order of the keys. |
OptionalProto
A value that may be absent. The same field numbers and types as SequenceProto, but each value field holds one value.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | name | string | LEN | The value’s name. |
| 2 | elem_type | int32 | VARINT | What the value is, with the same numbers as SequenceProto’s; 0 when absent. |
| 3 | tensor_value | TensorProto | LEN | The value, when TENSOR. |
| 4 | sparse_tensor_value | SparseTensorProto | LEN | The value, when SPARSE_TENSOR. |
| 5 | sequence_value | SequenceProto | LEN | The value, when SEQUENCE. |
| 6 | map_value | MapProto | LEN | The value, when MAP. |
| 7 | optional_value | OptionalProto | LEN | The value, when OPTIONAL. |