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

我目前正在尝试训练一个神经网络。我有一个文件名及其对应标签的数组。然而,当我试图训练网络时遇到了问题。

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×70 的一个 epoch 需要多长时间来加载?


回答:

看起来这是我提出的一个问题。在喂入数据时,输入队列运行器会挂起。这是由于你必须启动它。

根据这个问题,我们有:

引用:RudrakshTuwani
对于任何同样遇到这个问题的人,请阅读 girving 提到的文档。对于那些懒惰的人:

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

还有:

来自:girving
你可能需要启动队列运行器。请查看文档 https://www.tensorflow.org/versions/r0.11/how_tos/threading_and_queues/index.html

希望这对你有帮助!
pltrdy


请注意,在我的情况下,我感到困惑是因为原始代码使用的是:

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

而不是我(和你)使用的:

with tf.Session() as session:

前者实际上会隐式启动队列运行器。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注