【发布时间】:2018-03-26 11:22:59
【问题描述】:
我需要使用自定义输入和输出层扩展导出的模型。我发现这可以轻松完成:
with tf.Graph().as_default() as g1: # actual model
in1 = tf.placeholder(tf.float32,name="input")
ou1 = tf.add(in1,2.0,name="output")
with tf.Graph().as_default() as g2: # model for the new output layer
in2 = tf.placeholder(tf.float32,name="input")
ou2 = tf.add(in2,2.0,name="output")
gdef_1 = g1.as_graph_def()
gdef_2 = g2.as_graph_def()
with tf.Graph().as_default() as g_combined: #merge together
x = tf.placeholder(tf.float32, name="actual_input") # the new input layer
# Import gdef_1, which performs f(x).
# "input:0" and "output:0" are the names of tensors in gdef_1.
y, = tf.import_graph_def(gdef_1, input_map={"input:0": x},
return_elements=["output:0"])
# Import gdef_2, which performs g(y)
z, = tf.import_graph_def(gdef_2, input_map={"input:0": y},
return_elements=["output:0"])
sess = tf.Session(graph=g_combined)
print "result is: ", sess.run(z, {"actual_input:0":5}) #result is: 9
这很好用。
但是,我需要提供一个指针作为网络输入,而不是传递任意形状的数据集。问题是,我在 python 中想不出任何解决方案(定义和传递指针),并且在使用C++ Api 开发网络时,我找不到与tf.import_graph_def 函数等效的方法。
这在 C++ 中有不同的名称,还是有其他方法可以在 C++ 中合并两个图形/模型?
感谢您的建议
【问题讨论】:
标签: python c++ pointers tensorflow merge