Python 在tensorflow中使用具有MonitoredTrainingSession的数据集时无法馈送
下面是tensorflow 1.3.0的代码。您可以毫无错误地运行它。 但是如果取消对tf.summary.scalar'test'的注释,则下一批和检查点\u dir='/temp' 我得到 InvalidArgumentError有关回溯的信息,请参见上文:您必须为带有数据类型字符串的占位符张量“占位符”提供一个值 [[Node:Placeholder=Placeholder[dtype=DT_STRING,shape=[],_device=/job:localhost/replica:0/task:0/cpu:0]] 怎么了Python 在tensorflow中使用具有MonitoredTrainingSession的数据集时无法馈送,python,tensorflow,Python,Tensorflow,下面是tensorflow 1.3.0的代码。您可以毫无错误地运行它。 但是如果取消对tf.summary.scalar'test'的注释,则下一批和检查点\u dir='/temp' 我得到 InvalidArgumentError有关回溯的信息,请参见上文:您必须为带有数据类型字符串的占位符张量“占位符”提供一个值 [[Node:Placeholder=Placeholder[dtype=DT_STRING,shape=[],_device=/job:localhost/replica:0/
import tensorflow as tf
with tf.Graph().as_default():
global_step = tf.contrib.framework.get_or_create_global_step()
dataset_train = tf.contrib.data.Dataset.range(10)
dataset_val = tf.contrib.data.Dataset.range(90, 100)
iter_train_handle = dataset_train.make_one_shot_iterator().string_handle()
iter_val_handle = dataset_val.make_one_shot_iterator().string_handle()
handle = tf.placeholder(tf.string, shape=[])
iterator = tf.contrib.data.Iterator.from_string_handle(
handle, dataset_train.output_types, dataset_train.output_shapes)
next_batch = iterator.get_next()
# tf.summary.scalar('test', next_batch)
with tf.train.MonitoredTrainingSession(
# checkpoint_dir='/temp',
) as sess:
handle_train, handle_val = sess.run([iter_train_handle, iter_val_handle])
for step in range(10):
print('train', sess.run(next_batch, feed_dict={handle: handle_train}))
if step % 3 == 0:
print('val', sess.run(next_batch, feed_dict={handle: handle_val}))
从github获得答案。作者@asimshankar 也就是说,MonitoredTrainingSession运行摘要操作和 由于摘要操作已连接到占位符,因此 抱怨缺少饲料 如果不希望使用MonitoredTrainingSession的功能, 我可以建议直接使用MonitoredSession或Session吗 结束此操作,因为它不是bug或功能请求 MonitoredTrainingSession故意尝试运行摘要 定期操作 如果仍要使用MonitoredTrainingSession,则此问题的解决方法是将tf.placeholder_与默认值一起使用。使用合理的初始默认值,然后根据需要进行更新