能够在tensorflow中重用input_producer

时间:2016-09-09 06:11:28

标签: tensorflow

在Tensorflow培训中,我使用slice_input_producer来加载数据。我想运行我的数据集的一个纪元,在Python中执行一些计算,然后重复。我已经设置了这样的制作人:

input_queue = tf.train.slice_input_producer([images, labels], shuffle=False, num_epochs=1)

然后我想跑:

# Ideally this is all wrapped in a for loop:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
try:
    while not coord.should_stop():
        ... = sess.run(f(input_queue))
finally:
    # When done, ask the threads to stop.
    coord.request_stop()

# Wait for threads to finish.
coord.join(threads)

如果在第一次获取没有数据后我没有在每个循环中调用sess.run(tf.initialize_local_variables())。如果我这样做,那么我得到一个例外:

INFO in coordinator: Error reported to Coordinator: <class 'tensorflow.python.framework.errors.AbortedError'>, FIFOQueue '_0_input_producer/input_producer/fraction_of_32_full/fraction_of_32_full' is closed.
...
tensorflow.python.framework.errors.AbortedError: FIFOQueue '_0_input_producer/input_producer/fraction_of_32_full/fraction_of_32_full' is closed.
         [[Node: input_producer/input_producer/fraction_of_32_full/fraction_of_32_full_EnqueueMany = QueueEnqueueMany[Tcomponents=[DT_INT32], _class=["loc:@input_producer/input_producer/fraction_of_32_full/fraction_of_32_full"], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input_producer/input_producer/fraction_of_32_full/fraction_of_32_full, input_producer/input_producer/fraction_of_32_full/limit_epochs/_18)]]

可能是因为基础FIFOQueue已关闭。有没有办法重置队列或从图表中删除它?

这似乎有关:https://github.com/tensorflow/tensorflow/issues/2514

重新使用的替代方法可能只是从图表中移除queue_runner:Remove queue_runner from Tensorflow Graph

2 个答案:

答案 0 :(得分:0)

只需将"./dir"调整为代码中的纪元数:

来自文档:

  

num_epochs:一个整数(可选)。如果指定,slice_input_producer会在生成OutOfRange错误之前生成每个切片num_epochs次。如果未指定,slice_input_producer可以无限次地遍历切片。

protected void ddlcol2_SelectedIndexChanged(object sender, EventArgs e)
{
    string qry = "select * from Collections where col1='" + ddlcol1.SelectedValue.ToString() + "' and col2='" + ddlcol2.SelectedValue.ToString() + "'";
    SqlCommand cmd = new SqlCommand(qry,con);
    DataTable dt = new DataTable();
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    sda.Fill(dt);            
    Gridview1.DataSource = dt;
    Gridview1.DataBind();
}

答案 1 :(得分:0)

为什么不把它放在for循环中?

for looping_criterion in range(whenever):
  for input in range(one_epoch):
    y = sess.run(f(input_queue))
    .... maybe do other stuff

  # end of one epoch
  do_some_other_function()
#Code now loops back until it reaches whenever

否则,我不确定我是否理解您可以更新问题以扩展问题?