连接两个不同图tensorflow的输入和输出张量 [英] connect input and output tensors of two different graphs tensorflow
问题描述
我有 2 ProtoBuf 文件,我目前通过调用分别加载和转发每个文件 -
I have 2 ProtoBuf Files, I currently load and forward pass each of them separately, by calling-
out1=session.run(graph1out, feed_dict={graph1inp:inp1})
关注
final=session.run(graph2out, feed_dict={graph2inp:out1})
其中graph1inp和graph1out是图1的输入节点和输出节点> 和图 2
where graph1inp and graph1out are input node and output node of graph 1 and similar terminology for graph 2
现在,我想将 graph1out 与 graph2inp 连接起来,这样我只需运行 graph2out,同时用 inp1 喂养 graph1inp.换句话说,以这样一种方式连接 2 个涉及图的输入和输出张量,即一次运行足以在两个训练好的 ProtoBuf 文件上运行推理.
Now, I want to connect graph1out with graph2inp such that I only have to run graph2out while feeding graph1inp with inp1. In other words connecting the input and output tensors of the 2 involved graphs in such a way that one run is sufficient to run inference on both trained ProtoBuf files.
推荐答案
假设你的 Protobuf 文件包含序列化的 tf.GraphDef
protos,你可以使用tf.import_graph_def()
连接两个图:
Assuming that your Protobuf files contain serialized tf.GraphDef
protos, you can use the input_map
argument of tf.import_graph_def()
to connect the two graphs:
# Import graph1.
graph1_def = ... # tf.GraphDef object
out1_name = "..." # name of the graph1out tensor in graph1_def.
graph1out, = tf.import_graph_def(graph1_def, return_elements=[out_name])
# Import graph2 and connect it to graph1.
graph2_def = ... # tf.GraphDef object
inp2_name = "..." # name of the graph2inp tensor in graph2_def.
out2_name = "..." # name of the graph2out tensor in graph2_def.
graph2out, = tf.import_graph_def(graph2_def, input_map={inp2_name: graph1out},
return_elements=[out2_name])
这篇关于连接两个不同图tensorflow的输入和输出张量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!