我正在尝试dataset使用张量流从两个不同的来源获取数据。我写了下面的代码:
首先,我尝试了以下方法:
import tensorflow as tf
import numpy as np
iters = []
def return_data1():
d1 = tf.data.Dataset.range(1, 2000)
iter1 = d1.make_initializable_iterator()
iters.append(iter1)
data1 = iter1.get_next()
return data1
def return_data2():
d2 = tf.data.Dataset.range(2000, 4000)
iter2 = d2.make_initializable_iterator()
iters.append(iter2)
data2 = iter2.get_next()
return data2
test = tf.placeholder(dtype=tf.bool)
data = tf.cond(test, lambda: return_data1(), lambda: return_data2())
iter1 = iters[0]
iter2 = iters[1]
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
sess.run([iter1.initializer, iter2.initializer])
for i in range(2000):
if i < 1000:
print(sess.run(data, feed_dict={test: True}), "..")
else:
print(sess.run(data, feed_dict={test: False}), "--")
我得到了以下错误:
ValueError: Operation 'cond/MakeIterator' has been marked as not fetchable.
1-我想知道为什么我会出现这种现象。
ABOUTYOU
相关分类