如何使用 estimator API 在 tensorboard 上添加更多细节 [英] How to add more details on tensorboard using estimator API
问题描述
我按照 https://www.tensorflow.org/tutorials/estimators 创建了我的模型/cnn.
我在我的模型中添加了 SummarySaverHook
I added SummarySaverHook to my model
summary_hook = tf.train.SummarySaverHook(
100,
output_dir='C:/Users/dir',
summary_op=tf.summary.merge_all())
# Configure the Training Op (for TRAIN mode)
if mode == tf.estimator.ModeKeys.TRAIN:
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)
train_op = optimizer.minimize(
loss=loss,
global_step=tf.train.get_global_step())
return tf.estimator.EstimatorSpec(mode=mode, loss=loss, train_op=train_op, training_hooks=[summary_hook])
但是当我运行一个 get only enqueue_input 图(我不知道它是什么)和模型图时.我想要获得准确性和损失图表.
But when i run a get only enqueue_input chart(I don't known what is it) and model graph. I want get accuracy and loss charts.
所以我想在我的张量板中添加一些细节.
So i want a couple of details in my tensorboard.
- 损失和准确度字符
- 可以及时获得准确度图表,因为在估算器中,我只在最后一步之后才能获得准确度.
- 我能否在 tensorboard 中获得更多细节,比如错误的预测图像?但是没有 Session 和 Graph 创建,只能通过 estimator api?
推荐答案
首先,你不需要使用 summary_hook.您只需要在指定 logits 后立即使用 tf.metrics
指定所需的指标.
First of all, you don't need to use summary_hook. You just need to specify desired metrics with tf.metrics
right after you specify logits.
logits = tf.layers.dense(inputs=dropout, units=10)
predictions = {
"classes": tf.argmax(input=logits, axis=1),
"probabilities": tf.nn.softmax(logits, name="softmax_tensor")
}
accuracy = tf.metrics.accuracy(labels=labels, predictions=predictions['classes']
tf.summary.scalar('acc', accuracy[1])
然后把这个tf.logging.set_verbosity(tf.logging.INFO)
在您输入之后,如果您还没有这样做的话.
And put this
tf.logging.set_verbosity(tf.logging.INFO)
right after your inputs, if you haven't done so.
您可以通过将 eval_metric_ops = {'accuracy':accuracy}
dict 插入到 tf.estimator.EstimatorSpec
You can plot evaluation metrics by inserting eval_metric_ops = {'accuracy': accuracy}
dict to tf.estimator.EstimatorSpec
您可以使用 tf.summary
来可视化图像、权重和偏差等.
You can use tf.summary
for visualizing images, weights and biases, etc.
这篇关于如何使用 estimator API 在 tensorboard 上添加更多细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!