返回一個初始化默認圖的所有表的操作。
用法
tf.compat.v1.tables_initializer(
name='init_all_tables'
)
參數
-
name
初始化操作的可選名稱。
返回
- 一個初始化所有表的操作。請注意,如果沒有表,則返回的 Op 是 NoOp。
遷移到 TF2
警告:這個 API 是為 TensorFlow v1 設計的。繼續閱讀有關如何從該 API 遷移到本機 TensorFlow v2 等效項的詳細信息。見TensorFlow v1 到 TensorFlow v2 遷移指南有關如何遷移其餘代碼的說明。
即刻執行和 tf.function
不再需要 tf.compat.v1.tables_initializer
。在 TF2 中,當創建像 tf.lookup.StaticHashTable
這樣的可初始化表時,該表將在創建時自動初始化。
使用示例之前和之後
前:
with tf.compat.v1.Session():
init = tf.compat.v1.lookup.KeyValueTensorInitializer(['a', 'b'], [1, 2])
table = tf.compat.v1.lookup.StaticHashTable(init, default_value=-1)
tf.compat.v1.tables_initializer().run()
result = table.lookup(tf.constant(['a', 'c'])).eval()
result
array([ 1, -1], dtype=int32)
後:
init = tf.lookup.KeyValueTensorInitializer(['a', 'b'], [1, 2])
table = tf.lookup.StaticHashTable(init, default_value=-1)
table.lookup(tf.constant(['a', 'c'])).numpy()
array([ 1, -1], dtype=int32)
相關用法
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.get_or_create_global_step用法及代碼示例
- Python tf.compat.v1.tpu.bfloat16_scope用法及代碼示例
- Python tf.compat.v1.tpu.experimental.AdamParameters用法及代碼示例
- Python tf.compat.v1.train.cosine_decay_restarts用法及代碼示例
- Python tf.compat.v1.train.Optimizer用法及代碼示例
- Python tf.compat.v1.truncated_normal_initializer.from_config用法及代碼示例
- Python tf.compat.v1.tpu.experimental.embedding_column用法及代碼示例
- Python tf.compat.v1.train.AdagradOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.init_from_checkpoint用法及代碼示例
- Python tf.compat.v1.truncated_normal_initializer用法及代碼示例
- Python tf.compat.v1.train.Checkpoint用法及代碼示例
- Python tf.compat.v1.train.Supervisor.managed_session用法及代碼示例
- Python tf.compat.v1.tpu.experimental.FtrlParameters用法及代碼示例
- Python tf.compat.v1.train.Checkpoint.restore用法及代碼示例
- Python tf.compat.v1.train.global_step用法及代碼示例
- Python tf.compat.v1.to_int32用法及代碼示例
- Python tf.compat.v1.train.MonitoredSession.run_step_fn用法及代碼示例
- Python tf.compat.v1.train.RMSPropOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.exponential_decay用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.tables_initializer。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。