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

当前回答

献给那些还在努力获得操作系统的人。environ解决方案的工作,检查这是放在你导入tensorflow在你的脚本,就像mwweb的答案:

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

其他回答

通常的python3日志管理器为我工作tensorflow==1.11.0:

import logging
logging.getLogger('tensorflow').setLevel(logging.INFO)

为了兼容Tensorflow 2.0,你可以使用tf.get_logger

import logging
tf.get_logger().setLevel(logging.ERROR)

献给那些还在努力获得操作系统的人。environ解决方案的工作,检查这是放在你导入tensorflow在你的脚本,就像mwweb的答案:

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

是的,我正在使用tf 2.0 beta,并想启用/禁用默认日志记录。tf1中的环境变量和方法。X似乎不再存在了。

我在PDB中发现了这个方法:

# close the TF2 logger
tf2logger = tf.get_logger()
tf2logger.error('Close TF2 logger handlers')
tf2logger.root.removeHandler(tf2logger.root.handlers[0])

然后添加自己的日志记录器API(在本例中是基于文件的)

logtf = logging.getLogger('DST')
logtf.setLevel(logging.DEBUG)

# file handler
logfile='/tmp/tf_s.log'
fh = logging.FileHandler(logfile)
fh.setFormatter( logging.Formatter('fh %(asctime)s %(name)s %(filename)s:%(lineno)d :%(message)s') )
logtf.addHandler(fh)
logtf.info('writing to %s', logfile)

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

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

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