我正在使用tensorflow对经过训练的模型进行一些推断。
现在,我从张量流中得到结果,
def load_graph():
''' This method loads the graph '''
print 'load graphs'
pb_graphs = ['/Users/pm/Downloads/frozen_graph.pb']
graphs = []
for each in pb_graphs:
with tf.gfile.GFile(each, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(
graph_def,
input_map=None,
return_elements=None,
name=""
)
graphs.append(graph)
oos_graph = graphs[0]
print 'graph loaded'
return oos_graph
def run_inference(graph):
sess = tf.Session(graph=graph, config=tf.ConfigProto(log_device_placement=False))
# (1892, 11776),(1892, 12288),(1892, 12800),(1892, 13312),(1892, 9728)]:
for each in [(1892, 11264)]:
y,x = each
print y,x
y1 = y + 1024
x1 = x + 1024
pano_images = pano_img[y:y+1024,x:x+1024]
x_batch = pano_images.astype('float32')
pred_boxes = graph.get_tensor_by_name("decoder/cat:0")
pred_confs = graph.get_tensor_by_name("decoder/shape:0")
x = graph.get_tensor_by_name("x_in:0")
feed_dict_testing = {x: x_batch}
t1 = datetime.now()
np_pred_confs, np_pred_boxes = sess.run([pred_confs, pred_boxes], feed_dict=feed_dict_testing)
t2 = datetime.now()
delta = t2 - t1
print 'time taken in seconds == ', delta.total_seconds()
print 'np_pred_boxes ==', np_pred_boxes.shape
print 'np_pred_confs ==', np_pred_confs.shape
print 'np_pred_boxes ==', type(np_pred_boxes.shape)
print 'np_pred_confs ==', type(np_pred_confs.shape)
with sess.as_default():
img = Image.fromarray(pred_boxes.eval())
img.save('/Users/pm/Downloads/tf_image.png')
我想拍摄pred_box并生成图像,看看张量流预测了什么。
使用以下代码将张量流预测转换为图像即;将其转换为numpy数组并生成图像。
但它不起作用。读取我可以使用eval()函数将张量转换为numpy数组。
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'x_in' with dtype float and shape [1024,1024,3]
[[Node: x_in = Placeholder[dtype=DT_FLOAT, shape=[1024,1024,3], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]