具有更快查找和更高內存使用率的可變哈希表。
用法
tf.lookup.experimental.DenseHashTable(
key_dtype, value_dtype, default_value, empty_key, deleted_key,
initial_num_buckets=None, name='MutableDenseHashTable',
checkpoint=True, experimental_is_anonymous=False
)參數
-
key_dtype關鍵張量的類型。 -
value_dtype值張量的類型。 -
default_value表中缺少鍵時使用的值。 -
empty_key用於在內部表示空桶的鍵。不得用於插入、刪除或查找操作。 -
deleted_key用於在內部表示已刪除存儲桶的鍵。不得用於插入、刪除或查找操作,並且與 empty_key 不同。 -
initial_num_buckets桶的初始數量(可選,默認為 2^17=131072)。請注意,默認值相對較大(~1MB),因此如果您要創建許多表(可能是experimental_is_anonymous為True的情況),您應該將initial_num_buckets設置為較小的值以減少內存使用. -
name操作的名稱(可選)。 -
checkpoint如果為 True,則表的內容將保存到檢查點並從檢查點恢複。如果檢查點表的shared_name為空,則使用表節點名稱共享它。 -
experimental_is_anonymous是否對表使用匿名模式(默認為 False)。在匿名模式下,表資源隻能通過資源句柄訪問。它不能通過名字來查找。當所有指向該資源的資源句柄都消失時,該資源將被自動刪除。
拋出
-
ValueError如果檢查點為 True 且未指定名稱。
屬性
-
key_dtype表鍵數據類型。 -
name表的名稱。 -
resource_handle返回與此資源關聯的資源句柄。 -
value_dtype表值 dtype。
可以通過調用insert 方法插入數據,並通過調用remove 方法刪除數據。它不支持通過 init 方法進行初始化。
與 MutableHashTable , DenseHashTable 相比,通常提供更快的 insert , remove 和 lookup 操作,以換取更高的整體內存占用。
它使用帶有二次重新探測的"open addressing" 來解決衝突。這需要在鍵空間中指定兩個鍵 empty_key 和 deleted_key ,它們永遠不會插入到表中。
與MutableHashTable , DenseHashTable 不同的是,在檢查點和恢複操作期間創建的臨時張量不需要額外的內存。
示例用法:
table = tf.lookup.experimental.DenseHashTable(
key_dtype=tf.string,
value_dtype=tf.int64,
default_value=-1,
empty_key='',
deleted_key='$')
keys = tf.constant(['a', 'b', 'c'])
values = tf.constant([0, 1, 2], dtype=tf.int64)
table.insert(keys, values)
table.remove(tf.constant(['c']))
table.lookup(tf.constant(['a', 'b', 'c','d'])).numpy()
array([ 0, 1, -1, -1])
相關用法
- Python tf.lookup.experimental.MutableHashTable用法及代碼示例
- Python tf.lookup.experimental.MutableHashTable.lookup用法及代碼示例
- 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.DenseHashTable。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
