注冊用於將 base_type 的對象轉換為 Tensor 的函數。
用法
tf.register_tensor_conversion_function(
base_type, conversion_func, priority=100
)參數
-
base_typeconversion_func接受的所有對象的基本類型或基本類型元組。 -
conversion_func將base_type的實例轉換為Tensor的函數。 -
priority可選整數,指示應用此轉換函數的優先級。具有較小優先級值的轉換函數比具有較大優先級值的轉換函數運行得更早。默認為 100。
拋出
-
TypeError如果參數沒有適當的類型。
轉換函數必須具有以下簽名:
def conversion_func(value, dtype=None, name=None, as_ref=False):
# ...
如果指定,它必須返回帶有給定 dtype 的 Tensor。如果轉換函數創建一個新的 Tensor ,它應該使用給定的 name(如果指定)。所有異常都將傳播給調用者。
對於某些輸入,轉換函數可能會返回NotImplemented。在這種情況下,轉換過程將繼續嘗試後續的轉換函數。
如果 as_ref 為真,則函數必須返回 Tensor 引用,例如 Variable 。
注意:轉換函數將按優先級順序執行,然後是注冊順序。要確保轉換函數 F 在另一個轉換函數 G 之前運行,請確保 F 的注冊優先級低於 G 。
相關用法
- Python tf.reverse用法及代碼示例
- Python tf.reshape用法及代碼示例
- Python tf.reverse_sequence用法及代碼示例
- Python tf.repeat用法及代碼示例
- Python tf.recompute_grad用法及代碼示例
- Python tf.raw_ops.TPUReplicatedInput用法及代碼示例
- Python tf.raw_ops.Bitcast用法及代碼示例
- Python tf.raw_ops.SelfAdjointEigV2用法及代碼示例
- Python tf.raw_ops.BatchMatMul用法及代碼示例
- Python tf.raw_ops.OneHot用法及代碼示例
- Python tf.raw_ops.ResourceScatterNdSub用法及代碼示例
- Python tf.raw_ops.ReadVariableXlaSplitND用法及代碼示例
- Python tf.raw_ops.GatherV2用法及代碼示例
- Python tf.raw_ops.Expm1用法及代碼示例
- Python tf.range用法及代碼示例
- Python tf.raw_ops.BitwiseAnd用法及代碼示例
- Python tf.raw_ops.UniqueWithCounts用法及代碼示例
- Python tf.raw_ops.DecodeGif用法及代碼示例
- Python tf.random.truncated_normal用法及代碼示例
- Python tf.raw_ops.Size用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.register_tensor_conversion_function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
