【发布时间】:2017-04-28 03:22:05
【问题描述】:
我想在 tensorflow 教程给出的 cifar10 示例中每 固定数量的步骤 输出精度,我尝试在产生错误的钩子中使用 tf.summary.scalar(..):Graph is finalized。但是,我认为我只能访问钩子中的步骤数(我正在使用 cifar10_eval.py 评估准确性,也是 tensorflow 教程给出的示例代码)。我还尝试将global_step 写入检查点,但不幸的是MointeredTrainingSession 仅支持时间间隔(save_checkpoint_secs)而不是步长间隔。有什么建议吗?
cifar10_train.py
def train():
"""Train CIFAR-10 for a number of steps."""
with tf.Graph().as_default():
global_step = tf.contrib.framework.get_or_create_global_step()
# Build a Graph that trains the model with one batch of examples and
# updates the model parameters.
train_op = cifar10.train(loss, global_step)
class _LoggerHook(tf.train.SessionRunHook):
"""Logs loss and runtime."""
def begin(self):
self._step = -1
self._start_time = time.time()
def before_run(self, run_context):
self._step += 1
return tf.train.SessionRunArgs(loss) # Asks for loss value.
def after_run(self, run_context, run_values):
<output some information>
with tf.train.MonitoredTrainingSession(
checkpoint_dir=FLAGS.train_dir,
hooks=[tf.train.StopAtStepHook(last_step=FLAGS.max_steps),
tf.train.NanTensorHook(loss),
_LoggerHook()],
config=tf.ConfigProto(
log_device_placement=FLAGS.log_device_placement)) as mon_sess:
while not mon_sess.should_stop():
mon_sess.run(train_op)
【问题讨论】:
-
@SalvadorDali,这是 tensorflow 的 github 中的示例代码。我在我的工作副本中添加了
tf.summary(在print语句的正下方),但它不起作用。 -
@SalvadorDali 是的,我理解你的观点,但我认为这是最相关的部分,因为我的问题主要是关于如何在每个固定数量的步骤中评估模型的准确性,而不是为什么会出现错误当我在钩子中添加摘要时。
-
@SalvadorDali 正如你所建议的,我已经移出了一些不相关的代码
标签: python machine-learning tensorflow conv-neural-network