我想用tensorflow实现这样的目标。
我只能找到关于保存和恢复变量(权重)的文档。但是,和#2-2一样,我想利用隐藏层(张量)的输出作为另一个模型的输入。这能办到吗?
发布于 2017-01-16 08:13:05
据我所知,在创建了不同的计算图之后,不可能链接它们,但是,您有几个选项。
选项2:创建一个大图并使用控制流程op
output_layer, placeholder = build_my_model()
something = tf.where(output_layer < 0, do_something_1(), do_something_2())
上面所有函数调用都应该返回tensorflow操作。
Option2:在python中创建两个图并执行条件语句
# Build the first graph
with tf.Graph().as_default() as graph:
output_layer, placeholder = build_my_model()
# Build the second two graphs
with tf.Graph().as_default() as graph_1:
something_1 = do_something_1()
with tf.Graph().as_default() as graph_2:
something_2 = do_something_2()
因此,您还将得到三个不同的会话,并且需要将第一个会话的输出提供给另外两个会话中的一个。
# Get the output
_output_layer = sess.run(output_layer, {placeholder: ...})
if _output_layer < 0:
something = sess1.run(something_1, {...})
else:
something = sess2.run(something_2, {...})
正如您所看到的,如果您能够摆脱控制流op,那么您的代码就会简单得多。在一个图中包含所有内容的另一个优点是,整个图是可微的,您可以根据稍后阶段的丢失来训练模型第一阶段的参数。
https://stackoverflow.com/questions/41671631
复制相似问题