我使用Sonnet创建了一个简单的功能模块:
class MNISTEncoder(snt.AbstractModule):
def __init__(self,name='mnist_encoder'):
super(MNISTEncoder,self).__init__(name=name)
def _build(self,inputs,is_training):
normalizedData = tf.layers.batch_normalization(inputs, center=True,
scale=True,
training=is_training)
conv_A11 = tf.layers.conv2d(normalizedData, 32, [5, 5], name='conv5x5_0',
kernel_regularizer=tf.nn.l2_loss)
max_A12 = tf.layers.max_pooling2d(conv_A11, [2, 2], 2, name='max_2x2_0')
conv_A13 = tf.layers.conv2d(max_A12, 64, [5, 5], name='conv_5x5_1',
kernel_regularizer=tf.nn.l2_loss)
max_A14 = tf.layers.max_pooling2d(conv_A13, [2, 2], 2, name='max_2x2_1')
A1 = tf.layers.flatten(max_A14, 'A1')
dense_A21 = tf.layers.dense(A1, 1024, name='dense_1024')
drpt_A22 = tf.layers.dropout(dense_A21, 0.4, name='drpt_0.4',
training=is_training)
logits = tf.layers.dense(drpt_A22, 10, name='logits')
return logits
模块在tf.estimator model_fn中调用,如下所示:
#[...]
with tf.variable_scope('DLModel'):
mnistEncoder = MNISTEncoder('MainModule')
logits = mnistEncoder(dataTensor,trainingFlag)
output = tf.nn.softmax(logits, name='output')
这很好。但是,当我运行tensorboard时, Graph 选项卡中没有任何内容显示。我仍然可以在 Scalars 选项卡中看到模型的损失演变和其他标量摘要。如果我不使用Sonnet并将图层直接放在tf.estimator model_fn中,它可以很好地工作,我可以在tensorboard中看到我的模型图。 (我使用的是tensorflow,sonnet和tensorboard的最新版本(分别为版本1.4,1.4和1.0)。