问题描述
限时送ChatGPT账号..我正在尝试为我的张量流预测实现队列,但出现以下错误 -
I'm trying to implement queues for my tensorflow prediction but get the following error -
您必须使用 dtype float 和 shape [1024,1024,3] 为占位符张量 'in' 提供一个值
you must feed a value for placeholder tensor 'in' with dtype float and shape [1024,1024,3]
如果我使用 feed_dict,程序运行良好,尝试用队列替换 feed_dict.
The program works fine if I use the feed_dict, Trying to replace feed_dict with queues.
该程序基本上采用位置列表并将图像 np 数组传递给输入张量.
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, box = sess.run([p_confs, p_boxes], feed_dict=feed_dict_testing)
confs, boxes = sess.run([p_confs, p_boxes], feed_dict=feed_dict_testing)
推荐答案
我建议不要使用队列来解决这个问题,并切换到新的 tf.data
API.特别是 tf.data.Dataset.from_generator()
可以更轻松地从 Python 函数输入数据.您可以将代码重写得更简单,如下所示:
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()
请注意,在您的程序中,data
张量与您在 load_graph()
中加载的图形之间没有联系(至少,假设 load_graph()
不会从全局状态中获取 data
!).您可能需要使用 tf.import_graph_def()
和 input_map
参数,用于将 data
与冻结图中的张量之一(可能是 "in:0"
?)相关联以完成任务.
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.
这篇关于张量流错误 - 您必须为占位符张量“输入"提供一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论