在用 tensorflow 和 slim 训练了一些模型之后,我试图冻结模型和权重。但是我很难找到输出节点名称,这对于freeze_graph.freeze_graph()
.
我的输出层看起来像:
conv4_1 = slim.conv2d(net,num_outputs=2,kernel_size=[1,1],stride=1,scope='conv4_1',activation_fn=tf.nn.softmax)
#conv4_1 = slim.conv2d(net,num_outputs=1,kernel_size=[1,1],stride=1,scope='conv4_1',activation_fn=tf.nn.sigmoid)
print conv4_1.get_shape()
#batch*H*W*4
bbox_pred = slim.conv2d(net,num_outputs=4,kernel_size=[1,1],stride=1,scope='conv4_2',activation_fn=None)
conv4_1 是 softmaxed 类,无论是否面对。bbox_pred 是边界框回归。
当我保存图表tf.train.write_graph(self.sess.graph_def, output_path, 'model.pb')
并将 model.pb 作为文本打开时,我发现图表如下所示:
node {
name: "conv4_1/weights/Initializer/random_uniform/shape"
...
node {
name: "conv4_1/kernel/Regularizer/l2_regularizer"
...
node {
name: "conv4_1/Conv2D"
op: "Conv2D"
input: "conv3/add"
input: "conv4_1/weights/read"
...
node {
name: "conv4_1/Softmax"
op: "Softmax"
input: "conv4_1/Reshape"
...
node {
name: "Squeeze"
op: "Squeeze"
input: "conv4_1/Reshape_1"
attr {
key: "T"
value {
type: DT_FLOAT
}
}
attr {
key: "squeeze_dims"
value {
list {
i: 0
}
}
}
}
那么,问题来了,输出节点名称是什么?
tensorflow 只有编写层的方法才能设置“名称”,例如:
.conv(3, 3, 32, 1, 1, padding='VALID', relu=False, name='conv3')
.prelu(name='PReLU3')
.conv(1, 1, 2, 1, 1, relu=False, name='conv4-1')
.softmax(3,name='prob1'))
(self.feed('PReLU3') #pylint: disable=no-value-for-parameter
.conv(1, 1, 4, 1, 1, relu=False, name='conv4-2'))
但我在 tensorflow slim 中找不到设置输出名称的方法。
谢谢!