小编典典

禁用Tensorflow调试信息

python

通过调试信息,我的意思是TensorFlow在终端中显示的有关已加载的库和找到的设备等的内容,不是Python错误。

I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:900] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: 
name: Graphics Device
major: 5 minor: 2 memoryClockRate (GHz) 1.0885
pciBusID 0000:04:00.0
Total memory: 12.00GiB
Free memory: 11.83GiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:717] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Graphics Device, pci bus id: 0000:04:00.0)
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 1.0KiB
...

阅读 242

收藏
2020-12-20

共1个答案

小编典典

2.0更新(10/8/19) 设置TF_CPP_MIN_LOG_LEVEL仍然应该起作用(请参见v0.12 +更新中的以下内容),但是当前存在一个未解决的问题(请参阅问题#31870)。如果该设置TF_CPP_MIN_LOG_LEVEL对您不起作用(再次参见下文),请尝试执行以下操作来设置日志级别:

import tensorflow as tf
tf.get_logger().setLevel('INFO')

此外,请参阅有关tf.autograph.set_verbosity设置签名日志消息详细程度的文档-例如:

# Can also be set using the AUTOGRAPH_VERBOSITY environment variable
tf.autograph.set_verbosity(1)

v0.12 +更新(5/20/17),通过TF 2.0+运行:

在TensorFlow 0.12+中,根据此问题,您现在可以通过称为TF_CPP_MIN_LOG_LEVEL;的环境变量控制日志记录。它默认为0(显示所有日志),但可以设置为该Level列下的以下值之一。

  Level | Level for Humans | Level Description                  
 -------|------------------|------------------------------------ 
  0     | DEBUG            | [Default] Print all messages       
  1     | INFO             | Filter out INFO messages           
  2     | WARNING          | Filter out INFO & WARNING messages 
  3     | ERROR            | Filter out all messages      

请参阅以下使用Python的通用OS示例:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'  # or any {'0', '1', '2'}
import tensorflow as tf

为了更全面,您还调用了设置Pythontf_logging模块的级别,该模块用于摘要操作,张量板,各种估计器等。

# append to lines above
tf.logging.set_verbosity(tf.logging.ERROR)  # or any {DEBUG, INFO, WARN, ERROR, FATAL}

对于1.14,如果不按以下说明使用v1 API,则会收到警告:

# append to lines above
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)  # or any {DEBUG, INFO, WARN, ERROR, FATAL}

对于TensorFlow或TF-Learn日志的早期版本(v0.11.x或更低版本):
查看以下页面以获取有关TensorFlow日志记录的信息; 与新的更新,你能在日志记录级别设置为DEBUG,INFO,WARN,ERROR,或FATAL。例如:

tf.logging.set_verbosity(tf.logging.ERROR)

该页面还翻过了可与TF-Learn模型一起使用的监视器。这是页面。

但是,这不会阻止所有日志记录(仅TF-Learn)。我有两种解决方案;一种是“技术上正确”的解决方案(Linux),另一种是重建TensorFlow。

script -c 'python [FILENAME].py' | grep -v 'I tensorflow/'

对于其他,请参见此答案,其中涉及修改源和重建TensorFlow。

2020-12-20