【发布时间】:2018-05-02 22:24:52
【问题描述】:
我有一个卷积神经网络,我最近重构它以使用 Tensorflow 的 Estimator API,主要遵循 this tutorial。但是,在训练期间,我添加到 EstimatorSpec 的指标没有显示在 Tensorboard 上,并且似乎也没有在 tfdbg 中进行评估,尽管名称范围和指标存在于写入到 Tensorboard 的图表中。
model_fn的相关位如下:
...
predictions = tf.placeholder(tf.float32, [num_classes], name="predictions")
...
with tf.name_scope("metrics"):
predictions_rounded = tf.round(predictions)
accuracy = tf.metrics.accuracy(input_y, predictions_rounded, name='accuracy')
precision = tf.metrics.precision(input_y, predictions_rounded, name='precision')
recall = tf.metrics.recall(input_y, predictions_rounded, name='recall')
if mode == tf.estimator.ModeKeys.PREDICT:
spec = tf.estimator.EstimatorSpec(mode=mode,
predictions=predictions)
elif mode == tf.estimator.ModeKeys.TRAIN:
...
# if we're doing softmax vs sigmoid, we have different metrics
if cross_entropy == CrossEntropyType.SOFTMAX:
metrics = {
'accuracy': accuracy,
'precision': precision,
'recall': recall
}
elif cross_entropy == CrossEntropyType.SIGMOID:
metrics = {
'precision': precision,
'recall': recall
}
else:
raise NotImplementedError("Unrecognized cross entropy function: {}\t Available types are: SOFTMAX, SIGMOID".format(cross_entropy))
spec = tf.estimator.EstimatorSpec(mode=mode,
loss=loss,
train_op=train_op,
eval_metric_ops=metrics)
else:
raise NotImplementedError('ModeKey provided is not supported: {}'.format(mode))
return spec
有人对为什么不写这些有任何想法吗?我正在使用 Tensorflow 1.7 和 Python 3.5。我尝试通过tf.summary.scalar 显式添加它们,虽然它们确实以这种方式进入了 Tensorboard,但在第一次通过图表后它们永远不会更新。
【问题讨论】:
标签: python tensorflow