onnx.numpy_helper¶
|
将bf16(作为uint32)的ndarray转换为f32(作为uint32)。 |
|
将float8、e4m3(作为uint32)的ndarray转换为f32(作为uint32)。 |
|
将float8、e5m2(作为uint32)的ndarray转换为f32(作为uint32)。 |
|
将数组转换为TensorProto,包括在 |
|
将Python字典转换为映射定义。 |
|
将列表转换为序列 def。 |
|
将可选值转换为Optional def。 |
|
将张量定义对象转换为numpy数组。 |
|
将地图定义转换为Python字典。 |
|
将序列 def 转换为 Python 列表。 |
|
将可选的def转换为Python的可选类型。 |
数组¶
- onnx.numpy_helper.from_array(tensor: ndarray, name: str | None = None) TensorProto[source]¶
将数组转换为TensorProto,包括在
onnx._custom_element_types中定义的支持类型。- Parameters:
tensor – 一个numpy数组。
name – (可选)张量的名称。
- Returns:
转换后的张量定义。
- Return type:
- onnx.numpy_helper.to_array(tensor: TensorProto, base_dir: str = '') ndarray[源代码]¶
将张量定义对象转换为numpy数组。 支持在
onnx._custom_element_types中定义的类型。- Parameters:
tensor – 一个 TensorProto 对象。
base_dir – 如果存在外部张量,base_dir可以帮助找到它的路径
- Returns:
转换后的数组。
- Return type:
数组
由于numpy不支持ONNX中定义的所有类型(float 8类型、blofat16、int4、uint4、float4e2m1),这两个函数使用了在:mod:onnx._custom_element_types中定义的自定义dtype。
序列¶
- onnx.numpy_helper.to_list(sequence: SequenceProto) list[Any][source]¶
将序列 def 转换为 Python 列表。
- Parameters:
sequence – 一个 SequenceProto 对象。
- Returns:
转换后的列表。
- Return type:
字典¶
可选的¶
- onnx.numpy_helper.to_optional(optional: OptionalProto) Any | None[source]¶
将可选的def转换为Python的可选类型。
- Parameters:
optional – 一个 OptionalProto 对象。
- Returns:
转换后的可选。
- Return type:
opt
- onnx.numpy_helper.from_optional(opt: Any | None, name: str | None = None, dtype: int | None = None) OptionalProto[source]¶
将可选值转换为Optional def。
- Parameters:
opt – 一个Python可选参数
name – (可选)可选参数的名称。
dtype – (可选)输入元素的类型,用于在转换空值时指定可选值。dtype 必须是有效的 OptionalProto.DataType 值
- Returns:
转换后的可选定义。
- Return type:
可选的
工具¶
- onnx.numpy_helper.convert_endian(tensor: TensorProto) None[source]¶
调用以转换张量中原始数据的字节序。
- Parameters:
tensor – 要转换的TensorProto。
cast¶
- onnx.numpy_helper.bfloat16_to_float32(data: int16 | int32 | ndarray, dims: int | Sequence[int] | None = None) ndarray[source]¶
将bf16(作为uint32)的ndarray转换为f32(作为uint32)。
- Parameters:
data – 一个numpy数组,如果dims为None,则允许空维度。
dims – 如果指定,函数将重新调整结果。
- Returns:
如果dims为None,则返回一个具有相同维度的float32类型的numpy数组,如果指定了dims,则将其重塑为dims
- onnx.numpy_helper.float8e4m3_to_float32(data: int16 | int32 | ndarray, dims: int | Sequence[int] | None = None, fn: bool = True, uz: bool = False) ndarray[source]¶
将float8、e4m3(作为uint32)的ndarray转换为f32(作为uint32)。
有关技术细节,请参见8位存储的浮点数。
- Parameters:
data – 一个numpy数组,如果dims为None,则允许空维度。
dims – 如果指定,函数将重新调整结果。
fn – 没有无限值。
uz – 没有负零。
- Returns:
如果dims为None,则返回一个具有相同维度的float32类型的numpy数组,如果指定了dims,则将其重塑为dims。
- onnx.numpy_helper.float8e5m2_to_float32(data: int16 | int32 | ndarray, dims: int | Sequence[int] | None = None, fn: bool = False, uz: bool = False) ndarray[source]¶
将float8、e5m2(作为uint32)的ndarray转换为f32(作为uint32)。
请参阅8位存储的浮点数以获取技术细节。
- Parameters:
data – 一个numpy数组,如果dims为None,则允许空维度。
dims – 如果指定,函数将重新调整结果。
fn – 没有无限值。
uz – 没有负零。
- Returns:
如果dims为None,则返回一个具有相同维度的float32类型的numpy数组,如果指定了dims,则将其重塑为dims