Python 禁用keras或tensorflow输出
我知道在stackoverflow上已经有一些类似的问题了,但是没有一个解决了我的问题。在python脚本中,我必须多次训练keras模型,我希望在GPU支持下完成这项工作。每次我在输出控制台中看到一堆行,这让我很不安,因为我再也看不到有用的信息了。这是输出的一部分Python 禁用keras或tensorflow输出,python,tensorflow,keras,Python,Tensorflow,Keras,我知道在stackoverflow上已经有一些类似的问题了,但是没有一个解决了我的问题。在python脚本中,我必须多次训练keras模型,我希望在GPU支持下完成这项工作。每次我在输出控制台中看到一堆行,这让我很不安,因为我再也看不到有用的信息了。这是输出的一部分 2021-04-08 19:43:40.804324: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries a
2021-04-08 19:43:40.804324: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2021-04-08 19:43:40.804368: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2021-04-08 19:43:40.804409: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-04-08 19:43:40.804418: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0
2021-04-08 19:43:40.804424: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N
2021-04-08 19:43:40.804495: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:0 with 1356 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce MX250, pci bus id: 0000:06:00.0, compute capability: 6.1)
2021-04-08 19:45:27.918402: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: NVIDIA GeForce MX250 major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:06:00.0
我尝试了一些在互联网上找到的方法,包括以下方法,但都不管用
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
import logging
logging.getLogger("tensorflow").setLevel(logging.ERROR)
logging.getLogger("tensorflow").addHandler(logging.NullHandler(logging.ERROR))
欢迎提出任何建议
关于我的设置:
- python 3.6.8
- keras 2.3.1
- tensorflow 2.0.0
- cudatoolkit 10.0.130
中的本教程讨论如何使用元数据数据库(MLMD)API来防止输出的打印。这可能适用于您的应用程序。我使用这种简单的方法,适合我
# tacke future warning, deprecated warning, bla bla
import warnings
# ------------ tackle some noisy warning
def warn(*args, **kwargs):
pass
warnings.warn = warn
warnings.simplefilter(action="ignore", category=FutureWarning)
warnings.filterwarnings("ignore", category = DeprecationWarning)
'''
TF_CPP_MIN_LOG_LEVEL = 0 to all logs .
TF_CPP_MIN_LOG_LEVEL = 1 to filter out INFO logs
TF_CPP_MIN_LOG_LEVEL = 2 to additionall filter out WARNING
TF_CPP_MIN_LOG_LEVEL = 3 to additionally filter out ERROR.
'''
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
# now import tf
import tensorflow as tf
我发现tf的那些日志行很有用,也许你可以打印一些标记来查看旁边的值:打印(“=”*80)谢谢你的建议,但我更愿意去掉这些输出。谢谢你的回答。不幸的是,这并没有解决问题。你的tf版本是什么?我已经将此添加到我的问题中。我在那里找不到解决方案。你能更详细地描述一下你的意思吗?