在 Tensorflow 中添加整个训练/测试数据集的准确性摘要 [英] Add a summary of accuracy of the whole train/test dataset in Tensorflow
问题描述
我正在尝试使用 Tensorboard 来可视化我的训练过程.我的目的是,当每个 epoch 完成时,我想使用整个验证数据集来测试网络的准确性,并将此准确性结果存储到一个摘要文件中,以便我可以在 Tensorboard 中对其进行可视化.
I am trying to use Tensorboard to visualize my training procedure. My purpose is, when every epoch completed, I would like to test the network's accuracy using the whole validation dataset, and store this accuracy result into a summary file, so that I can visualize it in Tensorboard.
我知道 Tensorflow 有 summary_op
来做这件事,但是当运行代码 sess.run(summary_op)
时,它似乎只对一批有效.我需要计算整个数据集的准确度.怎么样?
I know Tensorflow has summary_op
to do it, however it seems only work for one batch when running the code sess.run(summary_op)
. I need to calculate the accuracy for the whole dataset. How?
有什么例子可以做到吗?
Is there any example to do it?
推荐答案
定义一个接受占位符的 tf.scalar_summary
:
Define a tf.scalar_summary
that accepts a placeholder:
accuracy_value_ = tf.placeholder(tf.float32, shape=())
accuracy_summary = tf.scalar_summary('accuracy', accuracy_value_)
然后计算整个数据集的准确率(定义一个例程,计算数据集中每批的准确率并提取平均值)并将其保存到python变量中,我们称之为va
.
Then calculate the accuracy for the whole dataset (define a routine that calculates the accuracy for every batch in the dataset and extract the mean value) and save it into a python variable, let's call it va
.
获得va
的值后,只需运行accuracy_summary
操作,输入accuracy_value_
占位符:
Once you have the value of va
, just run the accuracy_summary
op, feeding the accuracy_value_
placeholder:
sess.run(accuracy_summary, feed_dict={accuracy_value_: va})
这篇关于在 Tensorflow 中添加整个训练/测试数据集的准确性摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!