用法
@abc.abstractmethod
get_next_as_optional()
返回包裝在 tf.experimental.Optional
中的下一個元素。
如果迭代器已到達序列末尾,則返回的tf.experimental.Optional
將沒有值。
dataset = tf.data.Dataset.from_tensors(42)
iterator = iter(dataset)
optional = iterator.get_next_as_optional()
print(optional.has_value())
tf.Tensor(True, shape=(), dtype=bool)
print(optional.get_value())
tf.Tensor(42, shape=(), dtype=int32)
optional = iterator.get_next_as_optional()
print(optional.has_value())
tf.Tensor(False, shape=(), dtype=bool)
相關用法
- Python tf.data.Iterator.get_next用法及代碼示例
- Python tf.data.IteratorSpec用法及代碼示例
- Python tf.data.Dataset.take_while用法及代碼示例
- Python tf.data.experimental.RandomDataset.group_by_window用法及代碼示例
- Python tf.data.TFRecordDataset.filter用法及代碼示例
- Python tf.data.TextLineDataset.reduce用法及代碼示例
- Python tf.data.TextLineDataset.with_options用法及代碼示例
- Python tf.data.experimental.SqlDataset.enumerate用法及代碼示例
- Python tf.data.TextLineDataset.as_numpy_iterator用法及代碼示例
- Python tf.data.experimental.make_saveable_from_iterator用法及代碼示例
- Python tf.data.TextLineDataset.random用法及代碼示例
- Python tf.data.FixedLengthRecordDataset.repeat用法及代碼示例
- Python tf.data.TFRecordDataset.random用法及代碼示例
- Python tf.data.Dataset.cardinality用法及代碼示例
- Python tf.data.FixedLengthRecordDataset.cardinality用法及代碼示例
- Python tf.data.TextLineDataset.take_while用法及代碼示例
- Python tf.data.experimental.SqlDataset.zip用法及代碼示例
- Python tf.data.experimental.Counter用法及代碼示例
- Python tf.data.experimental.SqlDataset.shard用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.data.Iterator.get_next_as_optional。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。