本文介绍了Tensorflow:运行时测试指标和数据队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网络训练时计算和显示测试集的准确率.

I want to compute and display accuracy on the test set while the network is training.

MNIST 教程 使用提要,可以看到通过提供测试数据而不是训练数据可以轻松完成.简单问题的简单解决方案.

In the MNIST tutorial that uses feeds, one can see that it can be done easily by feeding test data rather than train data. Simple solution to a simple problem.

但是,在使用队列进行批处理时,我找不到这样简单的示例.AFAICS,文档提出了两种解决方案:

However I am not able to find such an easy example when using queues for batching. AFAICS, the documentation proposes two solutions:

  1. 具有保存状态的离线测试.我不想离线.
  2. 制作第二个测试"网络,与正在训练的网络共享权重.这听起来并不简单,我还没有看到这样的例子.

是否有第三种简单的方法可以在运行时计算测试指标?或者是否有第二个示例,具有共享权重的测试网络通过实现超级简单来证明我错了?

Is there a third, easy way to compute test metrics at run time? Or is there an example somewhere of the second, test network with shared weights that proves me wrong by being super simple to implement?

推荐答案

如果我正确理解您的问题,您想在使用队列输入而不是 feed_dict 进行训练时验证您的模型吗?请参阅我的 程序 执行此操作.这是一个简短的解释:

If I understand your question correctly, you want to validate your model while training with queue inputs not feed_dict?see my program that does this.Here is a short explanation:

首先,您需要将数据转换为训练和验证文件,例如train.tfreords"和valid.tfreocrds"

First you need to convert you data into train and validation files like 'train.tfreords' and 'valid.tfreocrds'

在你的训练计划中,第二个开始解析这两个文件的两个队列,并使用共享变量来获取训练和有效的两个对数

Second in your training program start two queues that parse this two files,and use sharing variables to get the two logits for train and valid

在我的程序中这是由

with tf.variable_scope("inference") as scope:
        logits = mnist.inference(images)
        scope.reuse_variables()
        validation_logits = mnist.inference(validation_images)

然后使用logits来做训练损失并最小化它并使用validation_logits来获得有效的准确性

then use logits to do get train loss and minimize it and use validation_logits to get valid accuracy

这篇关于Tensorflow:运行时测试指标和数据队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 03:29