用法
@staticmethod
from_string_handle(
string_handle, output_types, output_shapes=None, output_classes=None
)
參數
-
string_handle
tf.string
類型的標量tf.Tensor
,計算結果為由Iterator.string_handle()
方法生成的句柄。 -
output_types
tf.DType
對象的(嵌套)結構,對應於該數據集元素的每個組件。 -
output_shapes
(可選。)tf.TensorShape
對象的(嵌套)結構對應於此數據集元素的每個組件。如果省略,每個組件將具有不受約束的形狀。 -
output_classes
(可選。)Pythontype
對象的(嵌套)結構,對應於此迭代器元素的每個組件。如果省略,則假定每個組件的類型為tf.Tensor
。
返回
-
一個
Iterator
。
根據給定的句柄創建一個新的、未初始化的Iterator
。
此方法允許您定義 "feedable" 迭代器,您可以在其中通過在 tf.Session.run
調用中輸入值來在具體迭代器之間進行選擇。在這種情況下,string_handle
將是一個 tf.compat.v1.placeholder
,並且您將在每個步驟中為其提供 tf.data.Iterator.string_handle
的值。
例如,如果您有兩個迭代器分別標記訓練數據集和測試數據集中的當前位置,您可以選擇在每個步驟中使用哪個迭代器,如下所示:
train_iterator = tf.data.Dataset(...).make_one_shot_iterator()
train_iterator_handle = sess.run(train_iterator.string_handle())
test_iterator = tf.data.Dataset(...).make_one_shot_iterator()
test_iterator_handle = sess.run(test_iterator.string_handle())
handle = tf.compat.v1.placeholder(tf.string, shape=[])
iterator = tf.data.Iterator.from_string_handle(
handle, train_iterator.output_types)
next_element = iterator.get_next()
loss = f(next_element)
train_loss = sess.run(loss, feed_dict={handle:train_iterator_handle})
test_loss = sess.run(loss, feed_dict={handle:test_iterator_handle})
相關用法
- Python tf.compat.v1.data.Iterator.from_structure用法及代碼示例
- Python tf.compat.v1.data.Iterator.get_next用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.compat.v1.data.Dataset.snapshot用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.reduce用法及代碼示例
- Python tf.compat.v1.data.TextLineDataset.from_tensors用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.as_numpy_iterator用法及代碼示例
- Python tf.compat.v1.data.FixedLengthRecordDataset.skip用法及代碼示例
- Python tf.compat.v1.data.experimental.RandomDataset.bucket_by_sequence_length用法及代碼示例
- Python tf.compat.v1.data.Dataset.random用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.concatenate用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.cardinality用法及代碼示例
- Python tf.compat.v1.data.TextLineDataset.filter用法及代碼示例
- Python tf.compat.v1.data.experimental.RandomDataset.skip用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.padded_batch用法及代碼示例
- Python tf.compat.v1.data.FixedLengthRecordDataset.take用法及代碼示例
- Python tf.compat.v1.data.experimental.RandomDataset.scan用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.take用法及代碼示例
- Python tf.compat.v1.data.experimental.RandomDataset.padded_batch用法及代碼示例
- Python tf.compat.v1.data.FixedLengthRecordDataset.enumerate用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.data.Iterator.from_string_handle。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。