禁用keras或tensorflow输出

izkcnapc  于 2021-07-14  发布在  Java
关注(0)|答案(2)|浏览(406)

我知道在stackoverflow上已经有一些类似的问题,但是没有一个解决了我的问题。在python脚本中,我必须多次训练keras模型,并且我希望在gpu支持下完成这项工作。每次我在输出控制台得到一堆行,这是令人不安的,因为我看不到有用的信息了。这是输出的一部分。

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
km0tfn4u

km0tfn4u1#

我用这个简单的方法,对我有效。


# 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
x6yk4ghg

x6yk4ghg2#

tensorflow文档中的本教程讨论如何使用metadata db(mlmd)API来防止输出的打印。这可能适用于您的应用程序。

相关问题