Tensorflow日志消息不出现 [英] Tensorflow logging messages do not appear
问题描述
我使用随pip install
一起安装的tensorflow 1.2.0
.
当我运行包含
import logging
tf.logging.set_verbosity(tf.logging.INFO)
格式的日志消息
logging.info('TEST')
即使带有标志--tostderr
,也不会出现在终端输出中.
do not appear in the terminal output, even with the flag --tostderr
.
根据此答案我也尝试过
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '0'
但是问题仍然存在.有什么想法吗?
but still the problem persists. Any ideas?
推荐答案
TF日志记录基础:
因此,围绕张量流日志记录存在很多困惑,并且它确实没有得到很好的记录.我在搜索中登陆了几次,因此似乎是发布答案的好地方.
TF Logging Basics:
So there is a lot of confusion around tensorflow logging, and it is really not well documented. I landed here a few times in my searches, so it seems to be a good place to post an answer.
经过对Ubuntu和Windows的研究和试验(超出了我的计划),这就是我得到的:
After some research and experimentation with Ubuntu and Windows (more than I had planned), this is what I got:
有两个标志,名称相似,但语义有所不同:
There are two flags, similarly named, but with somewhat different semantics:
-
TF_CPP_MIN_LOG_LEVEL
-具有3或4个基本级别-低数字=更多消息.-
0
输出信息,警告,错误和致命信息(默认) -
1
输出警告,并且在 以上
-
2
输出错误及以上. - 等等...我没有检查边缘情况
TF_CPP_MIN_LOG_LEVEL
- which has 3 or 4 basic levels - low numbers = more messages.0
outputs Information, Warning, Error, and Fatals (default)1
outputs Warning, and above2
outputs Errors and above.- etc... I didn't check edge cases
-
3
输出很多东西 -
2
输出较少 -
1
输出更少 -
0
不输出任何多余内容(默认)
3
Outputs lots and lots of stuff2
Outputs less1
Outputs even less0
Outputs nothing extra (default)
- 由于所有VLOG消息都是信息性的,因此需要将LOG设置为0,以便您查看它们.幸运的是,这是默认设置.
- 这些错误归为标准错误,因此您可以使用以下方法将其重定向:
-
python tf-program.py &>mylog.log
- Since all the VLOG messages are Informational, then LOG needs to be set at 0 for you to see them. Fortunately that is the default.
- These errors go to the standard error so you can redirect them with something like:
python tf-program.py &>mylog.log
- 除了python的
os
模块未在Windows下拾取它们. Python从不爱Windows ...- 此代码序列在Windows中对我有效(并且肯定在Linux中适用):
-
import os
-
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '0'
-
os.environ['TF_CPP_MIN_VLOG_LEVEL'] = '3'
-
import tensorflow as tf
- Except python's
os
module did not pick them up under Windows. Python never loved Windows...- this code sequence works for me in Windows (and would surely work in Linux):
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '0'
os.environ['TF_CPP_MIN_VLOG_LEVEL'] = '3'
import tensorflow as tf
- 在Linux(bash)下,您可以在命令行上方便地指定这些内容,例如:
-
TF_CPP_MIN_VLOG_LEVEL=3 python tf-program.py
- Under Linux (bash) you can specify these conveniently on the command line, so with something like:
TF_CPP_MIN_VLOG_LEVEL=3 python tf-program.py
FWIW,我通过本教程在TensorFlow 1.7上进行了测试:
FWIW, I tested on TensorFlow 1.7 with this tutorial:
https://github.com/tensorflow/models/tree/master/tutorials/image/mnist
这是它的样子:
这篇关于Tensorflow日志消息不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-
- this code sequence works for me in Windows (and would surely work in Linux):
-
- 此代码序列在Windows中对我有效(并且肯定在Linux中适用):
-
-