gpt4 book ai didi

tensorflow - 如何在 Tensorflow 2 中更改日志级别

转载 作者:行者123 更新时间:2023-12-04 15:37:22 34 4
gpt4 key购买 nike

到目前为止我已经尝试过

import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)

import logging
import tensorflow as tf
logger = tf.get_logger()
logger.setLevel(logging.ERROR)

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

这些似乎都不起作用。

最佳答案

其实,tf.compat.v1.logging.set_verbosity作品。

请在以下位置找到代码 Logging Level设置为 10 i.e., DEBUG ,仅表示 all the Logs应该是 Printed :

import logging
import tensorflow as tf

tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.DEBUG)

tf.compat.v1.logging.error('Error Message')
tf.compat.v1.logging.info('Info Message')
tf.compat.v1.logging.warning('Warning Message')

如下图,它已经打印了所有的日志消息:
ERROR:tensorflow:Error Message
INFO:tensorflow:Info Message
WARNING:tensorflow:Warning Message

现在,让我们设置 Logging Level30, i.e., WARN
import logging
import tensorflow as tf

tf.compat.v1.logging.set_verbosity(30) # WARN

tf.compat.v1.logging.error('Error Message')
tf.compat.v1.logging.info('Info Message')
tf.compat.v1.logging.warning('Warning Message')

如下图, Info日志将被过滤和 Warning and Error Logs将打印:
ERROR:tensorflow:Error Message
WARNING:tensorflow:Warning Message

让我们设置 Logging Level40 i.e., ERROR
import logging
import tensorflow as tf

tf.compat.v1.logging.set_verbosity(40) # ERROR

tf.compat.v1.logging.error('Error Message')
tf.compat.v1.logging.info('Info Message')
tf.compat.v1.logging.warning('Warning Message')

现在,我们可以看到只有 Error Message打印:
ERROR:tensorflow:Error Message

希望这可以帮助。快乐学习!

关于tensorflow - 如何在 Tensorflow 2 中更改日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59326359/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com