输入队列不响应 TensorFlow 程序挂起

Input Queue not responding TensorFlow program hanging

我目前正在尝试训练神经网络。我有一组文件名及其相应的标签。但是我在尝试训练网络时遇到问题。

image_list, label_list = readImageLables()

images = ops.convert_to_tensor(image_list, dtype=dtypes.string)
labels = ops.convert_to_tensor(label_list, dtype=dtypes.int32)

with tf.Session() as sess:
    init_op = tf.initialize_all_variables()
    sess.run(init_op)
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess, coord=coord)
    for epoch in range(hm_epochs):
        epoch_loss = 0
        for _ in range(int(7685/batch_size)):
            print(labels.eval())
            filename_queue = tf.train.slice_input_producer([images,labels], num_epochs=10, shuffle=True)
            image,label = read_images_from_disk(filename_queue)
            print(image.eval())
            epoch_x, epoch_y = tf.train.batch([image, label], batch_size=batch_size)
            print("wait what")
            #imgs, lbls = epoch_x.eval(), epoch_y.eval()
            _, c = sess.run([optimizer, cost], feed_dict={x: epoch_x.eval(), y: epoch_y.eval()})
            epoch_loss += c

        print('Epoch', epoch, 'completed out of',hm_epochs,'loss:',epoch_loss)

在我尝试打印图像数据的那一行,程序挂起。即使删除了这一行,程序也会挂在我提供此数据的最后一个 sess.run 调用上。我已经初始化了队列运行器、协调器等。但是,我感觉 filename_queue 有问题。 tf.train.slice_input_producer 行中有什么我遗漏的吗?程序是挂了还是只是需要一段时间才能加载。加载批处理大小为 100 且图像为 80 x 70 的 epoch 通常需要多少时间?

看起来像是我打开的问题。在提供数据时,输入队列运行器挂起。这是因为您必须启动它。

issue,我们有:

Quoting: RudrakshTuwani
For anyone else struggling with this, please read the documentation as mentioned by girving. For the lazy ones:

init = tf.global_variables_initializer()
sess.run(init)
threads = tf.train.start_queue_runners()
print(sess.run(name_of_output_tensor))

以及:

From: girving
You probably need to start queue runners. Please see the documentation at https://www.tensorflow.org/versions/r0.11/how_tos/threading_and_queues/index.html

希望对您有所帮助!
pltrdy


请注意,在我的案例中,我感到困惑,因为 original code 使用的是:

sv = tf.train.Supervisor(logdir=FLAGS.save_path)
    with sv.managed_session() as session:

而不是我的(和你的):

with tf.Session() as session:

第一个实际上隐含地启动队列运行器。