通过调试信息,我指的是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
...

当前回答

我也遇到过这个问题(在tensorflow-0.10.0rc0上),但无法通过建议的答案修复过多的鼻子测试日志问题。

我设法通过直接探测张量流记录器来解决这个问题。不是最正确的修复,但工作很好,只污染直接或间接导入tensorflow的测试文件:

# Place this before directly or indirectly importing tensorflow
import logging
logging.getLogger("tensorflow").setLevel(logging.WARNING)

其他回答

因为TF_CPP_MIN_LOG_LEVEL对我没用,你可以试试:

tf.logging.set_verbosity(tf.logging.WARN)

在tensorflow v1.6.0中为我工作过

以上的解决方案都不能解决我在Jupyter Notebook中的问题,所以我使用以下来自Cicoria的代码片段,问题解决了。

import warnings  
with warnings.catch_warnings():  
    warnings.filterwarnings("ignore",category=FutureWarning)
    import tensorflow as tf
    from tensorflow import keras
    from tensorflow.keras.preprocessing.text import Tokenizer

print('Done') 

我为此挣扎了一段时间,尝试了这里几乎所有的解决方案,但无法摆脱TF 1.14中的调试信息,我尝试了以下多个解决方案:

import os
import logging
import sys

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'  # FATAL
stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')

import tensorflow as tf
tf.get_logger().setLevel(tf.compat.v1.logging.FATAL)
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
logging.getLogger('tensorflow').setLevel(tf.compat.v1.logging.FATAL)

sys.stderr = stderr

import absl.logging
logging.root.removeHandler(absl.logging._absl_handler)
absl.logging._warn_preinit_stderr = False

调试信息仍然显示,最终帮助我重新启动我的电脑(实际上重新启动内核应该工作)。所以如果有人有类似的问题,试着在你设置环境变量后重新启动内核,简单但可能不会想到。

可以通过os关闭所有调试日志。环境:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 
import tensorflow as tf

在tf 0.12和1.0上测试

在细节,

0 = all messages are logged (default behavior)
1 = INFO messages are not printed
2 = INFO and WARNING messages are not printed
3 = INFO, WARNING, and ERROR messages are not printed

如果你只需要清除屏幕上的警告输出,你可能想在导入tensorflow后立即使用这个简单的命令清除控制台屏幕(根据我的经验,它比禁用所有调试日志更有效):

在windows中:

import os
os.system('cls')

在Linux或Mac中:

import os
os.system('clear')