我无法使此代码正常工作,我在哪里错了?
dataset = tf.data.Dataset.from_tensors(np.arange(8))
dataset = dataset.apply(tf.contrib.data.sliding_window_batch(window_size=4))
iterator = dataset.make_one_shot_iterator()
element = iterator.get_next()
with tf.Session() as sess:
while True:
try:
print(sess.run(element))
except tf.errors.OutOfRangeError:
print('end')
break
我本来期望,[0,1,2,3],[1,2,3,4],...但是我什么也没得到。
编辑:如果我print(dataset)在apply得到之前<TensorDataset shapes: (8,), types: tf.int64>,之后apply得到<_SlideDataset shapes: (?, 8), types: tf.int64>,这不是我所期望的:应该是_SlideDatasetbe的形状(?, 4)吗?
相关分类