简体   繁体   English

tensorflow在队列训练时进行评估?

[英]tensorflow evaluate while training with queues?

I preprocessed my data as tfrecord. 我将我的数据预处理为tfrecord。 I feed my data by queue instead of feed_dict. 我通过队列 而不是feed_dict来提供数据。

This is my code. 这是我的代码。

for i in range(100000000):
    sess.run(train_op)
    start_time = time.time()
    if i > 20 and i % 10 == 0:
        summaries_train = sess.run(Summaries)
        writer_train.add_summary(summaries_train, i)
        print("%dth batch took %fs, have scanned %d of %d" % (i, time.time()-start_time, i*cf.batch_size, all))
        print("loss: {0}, acc: {1}".format(sess.run(Loss), sess.run(Acc)))

My Question is: How can I evaluate while training? 我的问题是:我如何评估培训?

When using queues, I don't have to write feed_dict. 使用队列时,我不必编写feed_dict。 So How can I feed evaluating data to tensorflow ? 那么如何将评估数据提供给张量流?

You can do something like eval_in_batches function here but where you take data from queue instead of feed_dict . 您可以在此处执行类似eval_in_batches函数的操作但是您可以从queue而不是feed_dict获取数据。 Note that you will want to have a separate queue so that your evaluation doesn't take examples from training. 请注意,您将需要一个单独的队列,以便您的评估不会从培训中获取示例。

Another common pattern to evaluate while training is to start a separate CPU-only process which loads checkpoints and runs the evaluation continuously. 培训时要评估的另一种常见模式是启动一个单独的仅CPU过程,该过程加载检查点并持续运行评估。

You can separate evaluation from training and even run it on a completely different machine/process. 您可以将评估与培训分开,甚至可以在完全不同的机器/过程上运行。 On your training machine (which has only training data) you periodically save your model to disk. 在训练机器上(仅包含训练数据),您可以定期将模型保存到磁盘。

Your evaluation machine checks the folder with your models and once a new model appears it loads it and runs evaluation. 您的评估机器会使用您的模型检查文件夹,一旦出现新模型,它就会加载它并运行评估。

All is the same as the training process except that you should 1) separate the training data and evaluation data; 除了你应该1)分离训练数据和评估数据之外,所有都与训练过程相同; 2) don't run the optimization operation, aka gradient descent. 2)不要运行优化操作,即梯度下降。 I hope this function may be of help for you. 我希望这个功能可能对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM