【问题标题】:tensorflow string_input_producer gives empty queuetensorflow string_input_producer 给出空队列
【发布时间】:2017-05-27 20:47:16
【问题描述】:

我正在尝试根据文件名列表在 tensorflow 中创建一个队列。该列表已创建,但字符串输入生产者似乎返回了一个空队列。代码不起作用可能还有其他原因。下面是代码:

sess = tf.InteractiveSession()

def read_my_file_format(filename_queue):
    reader = tf.WholeFileReader()
    key, value = reader.read(filename_queue)
    images = tf.image.decode_jpeg(value, channels=3)
    return images, key

def input_pipeline(filenames, batch_size, num_epochs, labels):
    filename_queue = tf.train.string_input_producer(filenames, num_epochs=num_epochs, shuffle=False)
    image, key = read_my_file_format(filename_queue)
    return image, key

sess.run(tf.global_variables_initializer())

coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess = sess, coord = coord, start=True)

input_pipeline(trainnames, batch_size, None, labels)

coord.request_stop()
coord.join(threads)

【问题讨论】:

    标签: python tensorflow computer-vision deep-learning image-recognition


    【解决方案1】:

    如果你能提供错误信息,那会有所帮助。

    同时,这里对你的代码做几点说明:

    • input_pipeline 方法定义了与您的队列关联的 TensorFlow 运算符并将它们添加到图表中,因此您应该在调用 sess.run(tf.global_variables_initializer())之前调用它,如果您希望队列成为图表的一部分并且在调用 @987654325 之前@如果你想让你的队列由协调器启动。
    • 您尚未要求 TensorFlow 实际运行您的 image, key 运算符。

    这是我要尝试的代码:

    sess = tf.InteractiveSession()
    
    def read_my_file_format(filename_queue):
        reader = tf.WholeFileReader()
        key, value = reader.read(filename_queue)
        images = tf.image.decode_jpeg(value, channels=3)
        return images, key
    
    def input_pipeline(filenames, batch_size, num_epochs, labels):
        filename_queue = tf.train.string_input_producer(filenames, num_epochs=num_epochs, shuffle=False)
        image, key = read_my_file_format(filename_queue)
        return image, key
    
    # Let us define the queue operators and add them to the default graph.
    image, key = input_pipeline(trainnames, batch_size, None, labels)
    
    sess.run(tf.global_variables_initializer())
    
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess = sess, coord = coord, start=True)
    
    # Let's run the image, key tensors.
    sess.run([image, key])
    
    coord.request_stop()
    coord.join(threads)
    

    【讨论】:

    • 你能告诉我如何将管道与图表结合起来吗?我了解到我们不能将张量提供给图形的占位符,在这种情况下,我应该如何为图形提供输入?我在两个不同的队列中有一个火车集和一个测试集,是否可以将它们都输入到一个图表中?如果我将一个图定义为一个函数,那么每次我调用它时它会创建一个新图还是返回相同的旧图?
    • 基本上,管道(例如filename_queueimagekey、...)是图表的一部分。如果您不想使用 feed_dict 手动输入占位符张量,您可以使用图像张量直接输入图形。基本上,您只需使用您的 dequeue 操作,就像您使用占位符一样。我建议阅读the reading_data section 并查看示例。关于您的最后一个问题,section 可能会引起您的兴趣。
    • 感谢您的帮助1我在打开问题之前已经阅读了该内容,但阅读后我仍然不确定该怎么做。所以我将把filename_queue、im​​age 和key 添加到图中。我想运行sess.run([image, key]) 将开始出列并通过图表?还是只是为了在没有训练的情况下获得图像张量?为了使管道成为图表的一部分,我没有找到如何同时给出训练集和测试集的管道,你知道吗?
    • 是的,它将运行出队操作并输出图像。如果你想对图中的图像做一些事情,你应该创建使用图像操作的新操作:train_op = use_image_to_train_model(image) 并调用sess.run(train_op)test_op = use_image_to_test_model(image) 并调用sess.run(test_op)
    猜你喜欢
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 1970-01-01
    相关资源
    最近更新 更多