张量流错误 - 您必须为占位符张量提供一个值 'in'

tensorflow error - you must feed a value for placeholder tensor 'in'

我正在尝试为我的 tensorflow 预测实现队列,但出现以下错误 -

您必须为占位符张量 'in' 提供 dtype float 和形状 [1024,1024,3]

的值

如果我使用 feed_dict,程序运行良好,尝试用队列替换 feed_dict。

该程序基本上采用位置列表并将图像 np 数组传递给输入张量。

for each in positions:          
    y,x = each          
    images = img[y:y+1024,x:x+1024,:]  
    a = images.astype('float32')

q = tf.FIFOQueue(capacity=200,dtypes=dtypes)
enqueue_op = q.enqueue(a)
qr = tf.train.QueueRunner(q, [enqueue_op] * 1)
tf.train.add_queue_runner(qr) 
data = q.dequeue()
graph=load_graph('/home/graph/frozen_graph.pb')


with tf.Session(graph=graph,config=tf.ConfigProto(log_device_placement=True)) as sess:
    p_boxes = graph.get_tensor_by_name("cat:0")
    p_confs = graph.get_tensor_by_name("sha:0")    
    y = [p_confs, p_boxes]
    x = graph.get_tensor_by_name("in:0")
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord,sess=sess)            
    confs, boxes = sess.run(y)
    coord.request_stop()
    coord.join(threads)

如何确保在会话中 运行 生成图形时识别填充到队列中的输入数据。

在我原来的运行中我称

confs, boxes = sess.run([p_confs, p_boxes], feed_dict=feed_dict_testing)

我建议不要使用队列来解决这个问题,而改用新的 tf.data API。特别是 tf.data.Dataset.from_generator() 可以更轻松地从 Python 函数输入数据。您可以重写您的代码以使其更简单,如下所示:

def generator():
  for y, x in positions:
    images = img[y:y+1024,x:x+1024,:]  
    yield images.astype('float32')

dataset = tf.data.Dataset.from_generator(
    generator, tf.float32, [1024, 1024, img.shape[3]])
# Add any extra transformations in here, like `dataset.batch()` or
# `dataset.repeat()`.
# ...
iterator = dataset.make_one_shot_iterator()
data = iterator.get_next()

请注意,在您的程序中,data 张量与您在 load_graph() 中加载的图形之间没有任何联系(至少,假设 load_graph() 没有抓取 data 来自全局状态!)。您可能需要使用 tf.import_graph_def()input_map 参数将 data 与冻结图中的张量之一关联(可能 "in:0"?)以完成任务。