【问题标题】:Display log into console with tf_logging使用 tf_logging 将日志显示到控制台
【发布时间】:2016-07-01 12:47:34
【问题描述】:

我正在玩slim.learning.train 并想在控制台中显示日志。根据源代码,这是使用tf_logging 模块完成的:

if 'should_log' in train_step_kwargs:
    if sess.run(train_step_kwargs['should_log']):
      logging.info('global step %d: loss = %.4f (%.2f sec)',
                   np_global_step, total_loss, time_elapsed) 

我可以运行我的训练循环,但控制台中没有日志。如何启用它?

【问题讨论】:

标签: tensorflow


【解决方案1】:

tf.logging.info() 转到 stderr,而不是 stdout,如下所述: https://groups.google.com/a/tensorflow.org/forum/#!msg/discuss/SO_JRts-VIs/JG1x8vOLDAAJ

我可以根据我的个人经验来验证这一点,我花了几个小时来玩弄 subprocess.Popen() 的参数版本,而不是捕获日志记录。对 stderr=PIPE 进行简单的更改就可以了,就像在我的具体示例中一样,您应该能够将其概括为您的问题。

training_results = Popen(cmds,shell=False,stderr=PIPE,bufsize=1,executable="python")
for line in iter(training_results.stderr.readline, b''):
  print line
  if line.startswith("INFO:tensorflow:Final test accuracy"):
    tf_final_acc = line
training_results.wait() # wait for the subprocess to exit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多