阻止Tensorflow向控制台输出信息

我一直在使用tensorflow,没有遇到任何问题,直到我添加了以下几行代码:

log_dir = os.path.join("logs",                       "fit",                       datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))tensorboard_callback = TensorBoard(log_dir)

运行这些代码后,控制台输出了大量信息。我查看了tf.keras.callbacks.TensorBoard文档,试图减少输出的冗余,但没有找到相关选项。

从各种stackoverflow答案中,我也尝试降低tf的冗余级别,但都没有成功:

tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)tf.get_logger().setLevel('ERROR')tf.autograph.set_verbosity(3)os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

我的环境配置如下:

Python = 3.8Tensorflow = 2.3.1Cuda Toolkit = 10.1 cuDNN = 7.6.4GPU=Nvidia RTX2060

控制台输出的信息都是I类型的消息,我已将这些消息粘贴如下,如果它们提供了重要细节的话。

2020-10-19 20:59:45.205887: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll2020-10-19 20:59:47.463539: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll2020-10-19 20:59:48.540417: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5coreClock: 1.2GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 312.97GiB/s2020-10-19 20:59:48.542360: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll2020-10-19 20:59:48.562444: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll2020-10-19 20:59:48.569770: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll2020-10-19 20:59:48.572530: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll2020-10-19 20:59:48.581126: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll2020-10-19 20:59:48.586315: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll2020-10-19 20:59:48.604682: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll2020-10-19 20:59:48.605112: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 02020-10-19 21:00:02.120333: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.2020-10-19 21:00:02.128143: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x255e4b0b0a0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:2020-10-19 21:00:02.128792: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version2020-10-19 21:00:03.014080: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5coreClock: 1.2GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 312.97GiB/s2020-10-19 21:00:03.014776: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll2020-10-19 21:00:03.015127: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll2020-10-19 21:00:03.015477: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll2020-10-19 21:00:03.015822: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll2020-10-19 21:00:03.016172: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll2020-10-19 21:00:03.016565: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll2020-10-19 21:00:03.016911: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll2020-10-19 21:00:03.017288: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 02020-10-19 21:00:03.722569: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:2020-10-19 21:00:03.722942: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]      0 2020-10-19 21:00:03.723166: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1276] 0:   N 2020-10-19 21:00:03.723522: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1402] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4594 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2060, pci bus id: 0000:01:00.0, compute capability: 7.5)2020-10-19 21:00:03.726833: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x255883632b0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:2020-10-19 21:00:03.727297: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce RTX 2060, Compute Capability 7.5

请问有人能帮我停止这些消息在控制台的输出吗?这些消息让分析控制台上的其他信息变得非常困难!

谢谢!


回答:

您可以使用os.environ来禁用调试日志。

可能的值如下:

0 = 记录所有消息(默认行为)1 = 不打印INFO消息2 = 不打印INFO和WARNING消息3 = 不打印INFO、WARNING和ERROR消息

Related Posts

自定义模型迁移学习中的热力图

在尝试为我的自定义模型生成Grad-CAM时,我遇到了…

递归特征消除错误 – “错误在{ : 任务1失败 – ‘by’参数符号错误”

非常感谢您提前提供的帮助。我目前正在处理一个包含794…

在TensorFlow 1.15中,将张量转换为NumPy数组以用于自定义训练循环

我正在使用TensorFlow训练一个模型,并希望在每…

tensorflow.keras.losses.cosine_similarity 在 TensorFlow 1.15 中返回正值

我不确定我是否做错了什么,但无论出于何种原因,当我按照…

在Tensorflow中构建2D到2D的神经网络模型 — 无效形状

我想在Tensorflow2中设计一个神经网络,将2D…

为什么我的神经网络准确率这么低?

我刚开始学习机器学习,最近一直在学习神经网络。这周我尝…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注