Tensorflow 张量流:简单的网络手术(去除第一层)
假设您有一个经过训练的网络,它由五个层组成,表示为L1->L2->L3->L4->L5。 这里,L1是输入层,由tf.placeholder组成 如何将中间层(如L3)的输出固定到用户指定的值,并运行前向传递以查看L5的输出值?换句话说,在这个场景中,我们希望将L3作为起始输入层,而完全忽略L1和L2 最后,假设不需要向后传球:也就是说,我们只想评估模型,而不想进一步训练模型Tensorflow 张量流:简单的网络手术(去除第一层),tensorflow,Tensorflow,假设您有一个经过训练的网络,它由五个层组成,表示为L1->L2->L3->L4->L5。 这里,L1是输入层,由tf.placeholder组成 如何将中间层(如L3)的输出固定到用户指定的值,并运行前向传递以查看L5的输出值?换句话说,在这个场景中,我们希望将L3作为起始输入层,而完全忽略L1和L2 最后,假设不需要向后传球:也就是说,我们只想评估模型,而不想进一步训练模型 谢谢 我们需要将L1和L2作为标识操作,并将输入直接传递给L3 我们需要使用检查点加载模型 graph = tf.Gr
谢谢 我们需要将L1和L2作为标识操作,并将输入直接传递给L3
graph = tf.Graph()
with graph.as_default():
saver = tf.train.import_meta_graph(checkpoint_path + '.meta')
session = tf.Session(graph=graph)
saver.restore(session, checkpoint_path)
graph_def = graph.as_graph_def()
for node in graph_def.node:
if node.name == "L3":
# Change its input from the output of L2 to the original input tensor op name.
node.input[1] = "input"
if node.name == "L1" or node.name == "L2":
# For L1 and L2, change its op to Identity
node.op = "Identity"
有关详细说明,请参阅
我们需要将L1和L2作为标识操作,并将输入直接传递给L3
graph = tf.Graph()
with graph.as_default():
saver = tf.train.import_meta_graph(checkpoint_path + '.meta')
session = tf.Session(graph=graph)
saver.restore(session, checkpoint_path)
graph_def = graph.as_graph_def()
for node in graph_def.node:
if node.name == "L3":
# Change its input from the output of L2 to the original input tensor op name.
node.input[1] = "input"
if node.name == "L1" or node.name == "L2":
# For L1 and L2, change its op to Identity
node.op = "Identity"
有关详细说明,请参阅
您可以使用
feed\u dict
将值直接馈送到L3。您还可以使用contrib.graph\u editor
重新布线,下面是一个示例——将L1和L2作为标识,并将值从用户传递到L1。您可以使用feed\u dict
将值直接传递到L3。您还可以使用contrib.graph\u editor
重新布线,下面是一个示例——将L1和L2作为标识,并将值从用户传递给L1