如何禁用过于冗长的 Tensorflow 2.4 日志记录?

时间:2021-04-30 14:13:49

标签: python tensorflow tensorflow2.x

我无法让 Tensorflow 2.4 使用不那么冗长的日志消息。 基本上,我希望显示更少的信息 (I) 日志消息,或仅显示警告 (W)。

到目前为止我尝试过的:

# (module imports...)
import tensorflow as tf
import os


# Source: https://stackoverflow.com/questions/38073432/how-to-suppress-verbose-tensorflow-logging
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"

# https://www.tensorflow.org/api_docs/python/tf/autograph/set_verbosity
os.environ["AUTOGRAPH_VERBOSITY"] = "0"

tf.get_logger().setLevel("WARNING")

# (every other code for the model)

我的环境:

- NVIDIA Docker container nvidia/cuda:11.2.1-cudnn8-devel-ubuntu18.04 where training is happening
- Tensorflow 2.4.0
- Python 3.8

实际结果:

2021-04-29 00:34:22.218556: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-04-29 00:34:22.218650: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-04-29 00:34:22.218683: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-04-29 00:34:22.218714: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-04-29 00:34:22.218746: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-04-29 00:34:22.218777: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2021-04-29 00:34:22.218809: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-04-29 00:34:22.218841: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-04-29 00:34:22.222104: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-04-29 00:34:22.222182: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-04-29 00:34:22.906654: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-04-29 00:34:22.906697: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267]      0 
2021-04-29 00:34:22.906707: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0:   N 

预期结果:

任何不那么冗长的东西。
任何导致日志消息减少的设置。
理想的解决方案:仅记录警告级别的消息。

0 个答案:

没有答案