我正在尝试使用一个例子TF文档 https://www.tensorflow.org/api_docs/python/tf/data/Dataset#window for tf.data.Dataset.window
并且文档中的示例失败了。
源自文档的代码:
import tensorflow as tf
ds = tf.data.Dataset.range(7).window(2)
next_element = ds.make_one_shot_iterator().get_next()
with tf.Session() as sess:
print(sess.run(next_element))
产生此错误(删除跟踪):
TypeError: Can not convert a _VariantDataset into a Tensor or Operation.
During handling of the above exception, another exception occurred:
TypeError: Fetch argument <_VariantDataset shapes: (), types: tf.int64> has invalid type <class 'tensorflow.python.data.ops.dataset_ops._VariantDataset'>, must be a string or Tensor. (Can not convert a _VariantDataset into a Tensor or Operation.)
So iterator.get_next()
正在返回一个VariantDataset
而不是通常的张量。
TF版本:1.13.1
Window 生成类似数据集的结构,在您的情况下应该返回对 {1, 2} 。不知道如何正确使用它或它为什么存在,但设法让它像这样工作:
将张量流导入为 tf
import tensorflow as tf
nxt = (tf.data.Dataset
.range(7)
.window(2, 1, 2, True)
.flat_map(lambda x: x.batch(2))
.make_one_shot_iterator()
.get_next()
)
with tf.Session() as sess:
print(sess.run(nxt))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)