用法
@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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。