一個通用的可變哈希表實現。
用法
tf.lookup.experimental.MutableHashTable(
key_dtype, value_dtype, default_value, name='MutableHashTable',
checkpoint=True, experimental_is_anonymous=False
)
參數
-
key_dtype
關鍵張量的類型。 -
value_dtype
值張量的類型。 -
default_value
表中缺少鍵時使用的值。 -
name
操作的名稱(可選)。 -
checkpoint
如果為 True,則表的內容將保存到檢查點並從檢查點恢複。如果檢查點表的shared_name
為空,則使用表節點名稱共享它。 -
experimental_is_anonymous
是否對表使用匿名模式(默認為 False)。在匿名模式下,表資源隻能通過資源句柄訪問。它不能通過名字來查找。當所有指向該資源的資源句柄都消失時,該資源將被自動刪除。
拋出
-
ValueError
如果檢查點為 True 且未指定名稱。
屬性
-
key_dtype
表鍵數據類型。 -
name
表的名稱。 -
resource_handle
返回與此資源關聯的資源句柄。 -
value_dtype
表值 dtype。
可以通過調用insert
方法插入數據,並通過調用remove
方法刪除數據。它不支持通過 init 方法進行初始化。
MutableHashTable
在檢查點和恢複操作期間需要額外的內存來創建臨時鍵和值張量。
示例用法:
table = tf.lookup.experimental.MutableHashTable(key_dtype=tf.string,
value_dtype=tf.int64,
default_value=-1)
keys_tensor = tf.constant(['a', 'b', 'c'])
vals_tensor = tf.constant([7, 8, 9], dtype=tf.int64)
input_tensor = tf.constant(['a', 'f'])
table.insert(keys_tensor, vals_tensor)
table.lookup(input_tensor).numpy()
array([ 7, -1])
table.remove(tf.constant(['c']))
table.lookup(keys_tensor).numpy()
array([ 7, 8, -1])
sorted(table.export()[0].numpy())
[b'a', b'b']
sorted(table.export()[1].numpy())
[7, 8]
相關用法
- Python tf.lookup.experimental.MutableHashTable.lookup用法及代碼示例
- Python tf.lookup.experimental.DenseHashTable用法及代碼示例
- Python tf.lookup.KeyValueTensorInitializer用法及代碼示例
- Python tf.lookup.TextFileInitializer用法及代碼示例
- Python tf.lookup.StaticHashTable用法及代碼示例
- Python tf.lookup.StaticVocabularyTable用法及代碼示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代碼示例
- Python tf.linalg.LinearOperatorIdentity.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorPermutation.solve用法及代碼示例
- Python tf.lite.Interpreter.get_signature_runner用法及代碼示例
- Python tf.lite.experimental.QuantizationDebugger用法及代碼示例
- Python tf.linalg.band_part用法及代碼示例
- Python tf.linalg.LinearOperatorKronecker.diag_part用法及代碼示例
- Python tf.linalg.lu_matrix_inverse用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.solvevec用法及代碼示例
- Python tf.lite.Interpreter.tensor用法及代碼示例
- Python tf.linalg.LinearOperatorLowerTriangular.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.solve用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.lookup.experimental.MutableHashTable。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。