onnx.numpy_helper¶
|
Converts an array into a TensorProto including supported type defined in |
|
Converts a Python dictionary into a map def. |
|
Converts a list into a sequence def. |
|
Converts an optional value into a Optional def. |
|
Converts a tensor def object to a numpy array. |
|
Converts a map def to a Python dictionary. |
|
Converts a sequence def to a Python list. |
|
Converts an optional def to a Python optional. |
array¶
- onnx.numpy_helper.from_array(tensor: ndarray, name: str | None = None) TensorProto [source]¶
Converts an array into a TensorProto including supported type defined in
onnx._custom_element_types
.- Parameters:
tensor – a numpy array.
name – (optional) the name of the tensor.
- Returns:
the converted tensor def.
- Return type:
- onnx.numpy_helper.to_array(tensor: TensorProto, base_dir: str = '') ndarray [source]¶
Converts a tensor def object to a numpy array. Supports types defined in
onnx._custom_element_types
.- Parameters:
tensor – a TensorProto object.
base_dir – if external tensor exists, base_dir can help to find the path to it
- Returns:
the converted array.
- Return type:
arr
As numpy does not support all the types defined in ONNX (float 8 types, blofat16, int4, uint4, float4e2m1),
these two functions use a custom dtype defined in :mod:onnx._custom_element_types
.
sequence¶
- onnx.numpy_helper.to_list(sequence: SequenceProto) list[Any] [source]¶
Converts a sequence def to a Python list.
- Parameters:
sequence – a SequenceProto object.
- Returns:
the converted list.
- Return type:
- onnx.numpy_helper.from_list(lst: list[Any], name: str | None = None, dtype: int | None = None) SequenceProto [source]¶
Converts a list into a sequence def.
- Parameters:
lst – a Python list
name – (optional) the name of the sequence.
dtype – (optional) type of element in the input list, used for specifying sequence values when converting an empty list.
- Returns:
the converted sequence def.
- Return type:
dictionary¶
optional¶
- onnx.numpy_helper.to_optional(optional: OptionalProto) Any | None [source]¶
Converts an optional def to a Python optional.
- Parameters:
optional – an OptionalProto object.
- Returns:
the converted optional.
- Return type:
opt
- onnx.numpy_helper.from_optional(opt: Any | None, name: str | None = None, dtype: int | None = None) OptionalProto [source]¶
Converts an optional value into a Optional def.
- Parameters:
opt – a Python optional
name – (optional) the name of the optional.
dtype – (optional) type of element in the input, used for specifying optional values when converting empty none. dtype must be a valid OptionalProto.DataType value
- Returns:
the converted optional def.
- Return type:
optional