禁用keras或tensorflow输出 [英] Disabling keras or tensorflow outputs

查看:147
本文介绍了禁用keras或tensorflow输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在stackoverflow上已经有一些类似的问题,但是没有一个问题解决了我的问题.在python脚本中,我必须多次训练keras模型,而我想在GPU支持下做到这一点.每次我在输出控制台中看到很多行时都会感到不安,因为我再也看不到有用的信息了.这是输出的一部分.

I know that there are already some similar questions here on stackoverflow but none of them solved my problem. In a python script, I have to train a keras model multiple times and I want to do this with GPU support. Each time I get a bunch of lines in the output console which is disturbing because I can not see the useful information anymore. Here is a part of the output.

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

我尝试了一些在互联网上发现的方法,包括以下方法,但对我没有任何帮助.

I tried some methods I found on the internet including the following, but nothing worked for me.

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

推荐答案

我使用这种简单的方法,对我有用.

I use this simple approach, works for me.

# 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

这篇关于禁用keras或tensorflow输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆