通过调试信息,我的意思是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: …Run Code Online (Sandbox Code Playgroud) 我正在设置python日志记录如下:
def setup_logging():
loggers = (logging.getLogger("amcat"), logging.getLogger("scrapers"),logging.getLogger(__name__))
filename = "somefile.txt"
sys.stderr = open(filename, 'a')
handlers = (logging.StreamHandler(sys.stdout),logging.FileHandler(filename))
formatter = AmcatFormatter(date = True)
for handler in handlers:
handler.setLevel(logging.INFO)
handler.setFormatter(formatter)
for logger in loggers:
logger.propagate = False
logger.setLevel(logging.INFO)
for handler in handlers:
logger.addHandler(handler)
logging.getLogger().handlers = []
Run Code Online (Sandbox Code Playgroud)
启用了2个主要模块记录器,它们都应该记录到控制台以及文件.错误被重定向到文件(理想情况下,错误也会显示在控制台中,但我还没有实现)
之后,我检查事情是否正确:
should_work = [
"amcat.scraping.scraper",
"amcat.scraping.htmltools",
"amcat.scraping.controller",
"__main__"]
loggerdict = logging.Logger.manager.loggerDict #all loggers
for name, logger in loggerdict.items():
if name in should_work:
print("\nlogger: "+name)
#iterate through parents see if effective handlers are set correctly
print(effectivehandlers(logger)) …Run Code Online (Sandbox Code Playgroud) 这是一个导致 Tensorflow 日志消息加倍的程序:
import tensorflow as tf
import logging
logging.basicConfig(level=logging.INFO)
tf.logging.info("tf version %s" % tf.__version__)
Run Code Online (Sandbox Code Playgroud)
输出:
INFO:tensorflow:tf version 1.4.0
INFO:tensorflow:tf version 1.4.0
Run Code Online (Sandbox Code Playgroud)
这个 stackoverflow 回答说 1) 关闭自定义记录器上的记录器传播;2)它将很快得到修复(2015 年 11 月,两年多前)。
我想关闭 Tensorflow 记录器上的日志消息传播,并发现这篇文章建议将以下内容作为仅针对 REPL 的 hack(即交互式):
INFO:tensorflow:tf version 1.4.0
INFO:tensorflow:tf version 1.4.0
Run Code Online (Sandbox Code Playgroud)
奇迹般有效。
但是..有更好的方法吗?