onnx.numpy_helper¶
|
將 bf16 (以 uint32 表示) 的 ndarray 轉換為 f32 (以 uint32 表示)。 |
|
將 float8, e4m3 (以 uint32 表示) 的 ndarray 轉換為 f32 (以 uint32 表示)。 |
|
將 float8, e5m2 (以 uint32 表示) 的 ndarray 轉換為 f32 (以 uint32 表示)。 |
|
將陣列轉換為 TensorProto,包括 |
|
將 Python 字典轉換為地圖定義。 |
|
將清單轉換為序列定義。 |
|
將可選值轉換為可選定義。 |
|
將張量定義物件轉換為 numpy 陣列。 |
|
將地圖定義轉換為 Python 字典。 |
|
將序列定義轉換為 Python 清單。 |
|
將可選定義轉換為 Python 可選值。 |
陣列¶
- onnx.numpy_helper.from_array(tensor: ndarray, name: str | None = None) TensorProto [原始碼]¶
將陣列轉換為 TensorProto,包括
onnx._custom_element_types
中定義的支援類型。- 參數:
tensor – numpy 陣列。
name – (選用) 張量的名稱。
- 傳回:
轉換後的張量定義。
- 傳回類型:
- onnx.numpy_helper.to_array(tensor: TensorProto, base_dir: str = '') ndarray [原始碼]¶
將張量定義物件轉換為 numpy 陣列。支援
onnx._custom_element_types
中定義的類型。- 參數:
tensor – TensorProto 物件。
base_dir – 如果外部張量存在,base_dir 可以協助尋找其路徑
- 傳回:
轉換後的陣列。
- 傳回類型:
arr
由於 numpy 不支援 ONNX 中定義的所有類型(float 8 類型、blofat16、int4、uint4、float4e2m1),這兩個函式使用 :mod:onnx._custom_element_types
中定義的自訂 dtype。
序列¶
- onnx.numpy_helper.to_list(sequence: SequenceProto) list[Any] [原始碼]¶
將序列定義轉換為 Python 清單。
- 參數:
sequence – SequenceProto 物件。
- 傳回:
轉換後的列表。
- 傳回類型:
字典¶
可選¶
- onnx.numpy_helper.to_optional(optional: OptionalProto) Any | None [原始碼]¶
將可選定義轉換為 Python 可選值。
- 參數:
optional – OptionalProto 物件。
- 傳回:
轉換後的可選值。
- 傳回類型:
opt
工具¶
- onnx.numpy_helper.convert_endian(tensor: TensorProto) None [原始碼]¶
呼叫以轉換張量中原始資料的位元組序。
- 參數:
tensor – 要轉換的 TensorProto。
轉換¶
- onnx.numpy_helper.bfloat16_to_float32(data: int16 | int32 | ndarray, dims: int | Sequence[int] | None = None) ndarray [原始碼]¶
將 bf16 (以 uint32 表示) 的 ndarray 轉換為 f32 (以 uint32 表示)。
- 參數:
data – NumPy 陣列,如果 dims 為 None,則允許空維度。
dims – 如果指定,則函式會重新塑形結果。
- 傳回:
如果 dims 為 None,則為具有相同維度的 float32 NumPy 陣列,如果指定,則重新塑形為 dims
- onnx.numpy_helper.float8e4m3_to_float32(data: int16 | int32 | ndarray, dims: int | Sequence[int] | None = None, fn: bool = True, uz: bool = False) ndarray [原始碼]¶
將 float8, e4m3 (以 uint32 表示) 的 ndarray 轉換為 f32 (以 uint32 表示)。
有關技術細節,請參閱 儲存在 8 位元中的浮點數。
- 參數:
data – NumPy 陣列,如果 dims 為 None,則允許空維度。
dims – 如果指定,則函式會重新塑形結果。
fn – 沒有無限值。
uz – 沒有負零。
- 傳回:
如果 dims 為 None,則為具有相同維度的 float32 NumPy 陣列,如果指定,則重新塑形為 dims。
- onnx.numpy_helper.float8e5m2_to_float32(data: int16 | int32 | ndarray, dims: int | Sequence[int] | None = None, fn: bool = False, uz: bool = False) ndarray [原始碼]¶
將 float8, e5m2 (以 uint32 表示) 的 ndarray 轉換為 f32 (以 uint32 表示)。
有關技術細節,請參閱 儲存在 8 位元中的浮點數。
- 參數:
data – NumPy 陣列,如果 dims 為 None,則允許空維度。
dims – 如果指定,則函式會重新塑形結果。
fn – 沒有無限值。
uz – 沒有負零。
- 傳回:
如果 dims 為 None,則為具有相同維度的 float32 NumPy 陣列,如果指定,則重新塑形為 dims