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

可紊 提交于 2019-12-11 14:14:10

问题


I'm trying to implement queues for my tensorflow prediction but get the following error -

you must feed a value for placeholder tensor 'in' with dtype float and shape [1024,1024,3]

The program works fine if I use the feed_dict, Trying to replace feed_dict with queues.

The program basically takes a list of positions and passes the image np array to the input tensor.

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)

How can I make sure the input data that I populated to the queue is recognized while running the graph in the session.

In my original run I call the

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


回答1:


I'd suggest not using queues for this problem, and switching to the new tf.data API. In particular tf.data.Dataset.from_generator() makes it easier to feed in data from a Python function. You can rewrite your code to be much simpler, as follows:

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()

Note that in your program, there's no connection between the data tensor and the graph you loaded in load_graph() (at least, assuming that load_graph() doesn't grab data from the global state!). You will probably need to use tf.import_graph_def() and the input_map argument to associate data with one of the tensors in your frozen graph (possibly "in:0"?) to complete the task.



来源:https://stackoverflow.com/questions/47315454/tensorflow-error-you-must-feed-a-value-for-placeholder-tensor-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!