每个 n-epoch 的 tensorflow 全连接控制流摘要 [英] tensorflow fully connected control flow per n-epoch summary

查看:35
本文介绍了每个 n-epoch 的 tensorflow 全连接控制流摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我不使用队列时,我喜欢在一个训练时期记录损失、准确度、ppv 等,并在每个时期结束时提交该 tf.summary.

When I don't use queues, I like to tally the loss, accuracy, ppv etc during an epoch of training and submit that tf.summary at the end of every epoch.

我不确定如何用队列复制这种行为.当一个时代结束时,我可以听到信号吗?

I'm not sure how to replicate this behavior with queues. Is there a signal I can listen to for when an epoch is complete?

(0.9 版)

典型设置如下:

queue=tf.string_input_producer(num_epochs=7)

...#build graph#...

...#build graph#...

#training
try:
    while not coord.should_stop():
        sess.run(train_op)
except:
    #file has been read num_epoch times
    #do some stuff.. maybe summaries
    coord.request_stop()
finally:
    coord.join(threads)

所以,显然我可以设置 num_epoch=1 并在 except 块中创建摘要.这将需要每个 epoch 运行一次我的整个程序,但不知何故它似乎不是最有效的.

So, clearly I could just set num_epoch=1 and create summaries in the except block. This would require running my entire program once per epoch and somehow it doesn't seem the most efficient.

推荐答案

EDIT 已更改以考虑对问题的编辑.

EDIT Changed to account for edits to the question.

纪元不是 TensorFlow 内置的或已知"的.您必须跟踪训练循环中的 epoch,并在 epoch 结束时运行摘要操作.像下面这样的伪代码应该可以工作:

An epoch is not something that is a built-in or 'known' to TensorFlow. You have to keep track of the epochs in your training loop and run the summary ops at the end of an epoch. A pseudo code like the following should work :

num_mini_batches_in_epoch = ... # something like examples_in_file / mini_batch_size
try:
    while True:
      for i in num_mini_batches_in_epoch:
        if coord.should_stop(): raise Exception()
        sess.run(train_op)
      sess.run([loss_summary, accuracy_summary])
except:
    #file has been read num_epoch times
    #do some stuff.. maybe summaries
    coord.request_stop()
finally:
    coord.join(threads)

这篇关于每个 n-epoch 的 tensorflow 全连接控制流摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆