2017-08-10 94 views
0

我是tensorflow的新手,目前正试图从我的数据中生成csv格式的批次。在TensorFlow中,为什么tf.train.shuffle_batch会永久挂起,并且不会返回批次?

我遵循Tensor Flow的Reading Data Tutorial(https://www.tensorflow.org/programmers_guide/reading_data),但由于我的代码永远存在,我一定误解了一些东西。 我使用了教程中的read_my_file_format函数,它工作正常。现在我想训练我的网络实际使用批处理如下:

def input_pipeline(filenames, batch_size, num_epochs=None): 
    filename_queue = tf.train.string_input_producer(
     filenames, num_epochs=num_epochs, shuffle=True) 
example, label = read_my_file_format(filename_queue) 
print('read_my_file is done') 
min_after_dequeue = 10 
capacity = min_after_dequeue + 3 * batch_size 
example_batch, label_batch = tf.train.shuffle_batch(
    [example, label], batch_size=batch_size, capacity=capacity, 
    min_after_dequeue=min_after_dequeue) 
print('all done but the return') 
return example_batch, label_batch 

with tf.Session() as sess: 
batch_size=5 
# Start populating the filename queue. 
coord = tf.train.Coordinator() 
threads = tf.train.start_queue_runners(coord=coord) 

batch_data,batch_label=sess.run(input_pipeline(file_name,batch_size=batch_size)) 
print('return is done') 
print(batch_data,batch_label) 
coord.request_stop() 
coord.join(threads) 

要进行调试的缘故,在上面的代码,我只是想打印的批量输出没有把它送入网络。用我的印刷品,我能够看到它挂起的位置: 返回example_batch,label_batch之前。

我的神经网络已准备就绪,我的数据已经处理完毕,所以这是唯一让我无法继续前进的项目(超新星分类)。你有什么建议或建议吗?我一直坚持这一点。

此外,如果需要,我只有一个输入文件在我的文件名。

谢谢

+0

您确定它不会在'read_my_file_format'函数中挂起,并且将正确的'file_names'传递给'input_pipeline'吗? – eaksan

+0

是的,我检查了这一点,它走出了read_my_file_format:/ – EliseB

回答

0

您需要初始化变量。

with tf.Session() as sess: 
    ... 
    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(sess=sess, coord=coord) 
    sess.run(tf.global_variables_initializer()) 
    ... 
+0

我会试试这个谢谢你!其实,昨天我把tf.Session()改为 asss: batch_size = 5 #开始填充文件名队列。 坐标= tf.train.Coordinator() batch_data,batch_label = input_pipeline(FILE_NAME,=的batch_size的batch_size) 线程= tf.train.start_queue_runners(坐标=坐标) batch_data = sess.run(batch_data) batch_labell = sess.run(batch_label) 它的工作!你知道为什么吗? – EliseB

+0

现在我试着添加num_epochs。尽可能多的人得到“FailedPreconditionError”>,尝试使用未初始化的值input_producer_2/limit_epochs/epochs“。我读过,这个问题就解决了通过初始化它我一样遵循所有变量: “init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer()) sess.run(init_op)” 但我仍然得到同样的错误,为什么?对所有这些问题抱歉。 – EliseB

+0

确定您在定义导致问题的操作后运行初始化操作。从错误消息看来,你没有在适当的地方运行初始化操作。 –

相关问题