我需要使用自定义输入和输出层来扩展导出的模型。我已经发现可以通过以下方式轻松地完成:
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++中合并两个图/模型的方式是否有其他方法?
感谢任何建议。