python - Tensorflow string_input_ Producer 卡在队列中

标签 python tensorflow deep-learning

通过遵循 mnist 示例,我能够构建自定义网络并使用示例的 inputs 函数加载我的数据集(之前编码为 TFRecord) 。回顾一下,inputs 函数如下所示:

def inputs(train_dir, train, batch_size, num_epochs, one_hot_labels=False):

    if not num_epochs: num_epochs = None
    filename = os.path.join(train_dir,
                        TRAIN_FILE if train else VALIDATION_FILE)

    with tf.name_scope('input'):
        filename_queue = tf.train.string_input_producer(
            [filename], num_epochs=num_epochs)

        # Even when reading in multiple threads, share the filename
        # queue.
        image, label = read_and_decode(filename_queue)

        # Shuffle the examples and collect them into batch_size batches.
        # (Internally uses a RandomShuffleQueue.)
        # We run this in two threads to avoid being a bottleneck.
        images, sparse_labels = tf.train.shuffle_batch(
            [image, label], batch_size=batch_size, num_threads=2,
            capacity=1000 + 3 * batch_size,
            # Ensures a minimum amount of shuffling of examples.
            min_after_dequeue=1000)

    return images, sparse_labels

然后,在培训期间,我声明了培训运算符(operator)并运行了所有内容,一切都很顺利。

现在,我尝试使用相同的函数在相同的数据上训练不同的网络,唯一(主要)的区别是,而不是仅仅调用 slim.learning.train 函数在某些train_operator上,我手动进行训练(通过手动评估损失并更新参数)。架构更加复杂,我被迫这样做。

当我尝试使用inputs函数生成的数据时,程序卡住了,设置队列超时确实表明它卡在了生产者的队列上。 这让我相信我可能错过了有关 tensorflow 中生产者的使用的一些内容,我已经阅读了教程,但我无法弄清楚这个问题。是否有某种调用 slim.learning.train 所做的初始化,并且如果我手动进行训练,我需要手动复制?到底为什么制片人不生产?

例如,执行以下操作:

imgs, labels = inputs(...)
print imgs

打印

<tf.Tensor 'input/shuffle_batch:0' shape=(1, 128, 384, 6) dtype=float32>

这是正确的(符号?)张量,但如果我尝试使用 imgs.eval() 获取实际数据,它就会无限期地卡住。

最佳答案

您需要启动队列运行程序,否则队列将为空并且从中读取数据将挂起。请参阅the documentation on queue runners .

关于python - Tensorflow string_input_ Producer 卡在队列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40731891/

相关文章:

python - Pandas 使用日期列通过 .shift 创建天列

python - 没有名为 ev3dev2 的模块

tensorflow - CNN 模型的 val_loss 下降得很好,但 val_loss 变化很大

python - pandas 与 numpy 的不同标准

python - 如何给函数命名?

tensorflow - 从零开始训练 Resnet 深度神经网络

python - 从预训练模型进行微调后,TensorFlow 模型中的输出节点名称丢失

python - 在Keras中执行最新的 "Lookahead Optimizer"论文?

python - 如何在Keras中设置预测阈值?

python - keras 层在每个 epoch 重新启动一部分权重