我已经构建了一个张量流神经网络,现在想要在其上运行graph_util.convert_variables_to_constants
函数。但是,这需要output_node_names
参数。网络中的最后一层名称为logit
,其构建如下:
logits = tf.layers.dense(inputs=dropout, units=5, name='logit')
但是该范围内有许多节点:
gd = sess.graph_def
for n in gd.node:
if 'logit' in n.name:print(n.name)
打印:
logit/kernel/Initializer/random_uniform/shape
logit/kernel/Initializer/random_uniform/min
logit/kernel/Initializer/random_uniform/max
logit/kernel/Initializer/random_uniform/RandomUniform
logit/kernel/Initializer/random_uniform/sub
logit/kernel/Initializer/random_uniform/mul
logit/kernel/Initializer/random_uniform
logit/kernel
logit/kernel/Assign
logit/kernel/read
logit/bias/Initializer/zeros
logit/bias
logit/bias/Assign
logit/bias/read
logit/Tensordot/Shape
logit/Tensordot/Rank
logit/Tensordot/axes
...
logit/Tensordot/Reshape_1
logit/Tensordot/MatMul
logit/Tensordot/Const_2
logit/Tensordot/concat_2/axis
logit/Tensordot/concat_2
logit/Tensordot
logit/BiasAdd
...
如何确定哪些节点是输出节点?
答案 0 :(得分:1)
如果图形很复杂,通常的方法是在最后添加一个标识节点:
output = tf.identity(logits, 'output')
# you can use the name "output"
例如,以下代码应该有效:
logits = tf.layers.dense(inputs=dropout, units=5, name='logit')
output = tf.identity(logits, 'output')
output_graph_def = tf.graph_util.convert_variables_to_constants(
ss, tf.get_default_graph().as_graph_def(), ['output'])