在tensorflow中实现屏蔽输出的log信息
作者:-牧野- 发布时间:2023-02-27 17:41:21
标签:tensorflow,屏蔽,输出,log
tensorflow中可以通过配置环境变量 'TF_CPP_MIN_LOG_LEVEL' 的值,控制tensorflow是否屏蔽通知信息、警告、报错等输出信息。
使用方法:
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # or any {'0', '1', '2'}
TF_CPP_MIN_LOG_LEVEL 取值 0 : 0也是默认值,输出所有信息
TF_CPP_MIN_LOG_LEVEL 取值 1 : 屏蔽通知信息
TF_CPP_MIN_LOG_LEVEL 取值 2 : 屏蔽通知信息和警告信息
TF_CPP_MIN_LOG_LEVEL 取值 3 : 屏蔽通知信息、警告信息和报错信息
测试代码:
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '0'
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
v1 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v1')
v2 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v2')
sumV12 = v1 + v2
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
print sess.run(sumV12)
TF_CPP_MIN_LOG_LEVEL 为 0 的输出:
2018-04-21 14:59:09.910415: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.910442: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.910448: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.910453: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.910457: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.911260: I tensorflow/core/common_runtime/direct_session.cc:300] Device mapping:
2018-04-21 14:59:09.911816: I tensorflow/core/common_runtime/simple_placer.cc:872] add: (Add)/job:localhost/replica:0/task:0/cpu:0
2018-04-21 14:59:09.911835: I tensorflow/core/common_runtime/simple_placer.cc:872] v2: (Const)/job:localhost/replica:0/task:0/cpu:0
2018-04-21 14:59:09.911841: I tensorflow/core/common_runtime/simple_placer.cc:872] v1: (Const)/job:localhost/replica:0/task:0/cpu:0
Device mapping: no known devices.
add: (Add): /job:localhost/replica:0/task:0/cpu:0
v2: (Const): /job:localhost/replica:0/task:0/cpu:0
v1: (Const): /job:localhost/replica:0/task:0/cpu:0
[ 2. 4. 6.]
值为0也是默认的输出,分为三部分,一个是警告信息说没有优化加速,二是通知信息告知操作所用的设备,三是程序中代码指定要输出的结果信息
TF_CPP_MIN_LOG_LEVEL 为 1 的输出,没有通知信息了:
2018-04-21 14:59:09.910415: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.910442: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.910448: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.910453: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-04-21 14:59:09.910457: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
Device mapping: no known devices.
add: (Add): /job:localhost/replica:0/task:0/cpu:0
v2: (Const): /job:localhost/replica:0/task:0/cpu:0
v1: (Const): /job:localhost/replica:0/task:0/cpu:0
[ 2. 4. 6.]
TF_CPP_MIN_LOG_LEVEL 为 2和3 的输出,设置为2就没有警告信息了,设置为3警告和报错信息(如果有)就都没有了:
Device mapping: no known devices.
add: (Add): /job:localhost/replica:0/task:0/cpu:0
v2: (Const): /job:localhost/replica:0/task:0/cpu:0
v1: (Const): /job:localhost/replica:0/task:0/cpu:0
[ 2. 4. 6.]
来源:https://blog.csdn.net/dcrmg/article/details/80029741
0
投稿
猜你喜欢
- 目的我们的目标是安装一个允许我们托管多个网站的web服务器,其中一些是针对电子商务的安全解决方案,而大部分网站是通过连接一个数据库服务器并且
- 最近给卫生局做一个表格上传/可视化系统,算是小有成果。今天把项目中的文件拖拽上传模块分离出来,做了一个独立的小demo,并把相关代码打包上传
- 我用 ip=Request.ServerVariables
- 下面这段代码能够显示,当前用户所能够看到的所有的用户和表有兴趣的, 可以把每个表的内容加上<% Dim objOraSess
- 以前工作的时候由于Oracle8i数据库经常出现用户过多的错误,由于数据量大,经常出现ORA:12500错误,但主要原因是访问过多而引起的,
- 概述从今天开始, 小白我将带领大家一起来补充一下 数据库的知识.数据控制语言数据控制语言 (Data Control Language) 是
- IE测试通过,FF有点小BUGCls_Leibie.asp代码如下:<% '数据库字段为类属性,添加、删除、修改、操
- python中不存在所谓的传值调用,一切传递的都是对象的引用,也可以认为是传址。一、可变对象和不可变对象Python在heap中分配的对象分
- 本文实例讲述了Python 私有化操作。分享给大家供大家参考,具体如下:私有化xx: 公有变量_x: 单前置下划线,私有化属性或方法,fro
- WEB开发者不光要解决程序的效率问题,对数据库的快速访问和相应也是一个大问题。希望本文能对大家掌握MySQL优化技巧有所帮助。1. 优化你的
- 前言最近将使用爬虫爬取的链接保存到 mysql 数据库中时,发现我将链接使用 json_encode 保存时候,在数据库中却显示了转义字符,
- 1. 鼠标的哪个按键被点击?<html><head><script type="text/javas
- 功能所在位置该功能运用了django.contrib.messages这个库,再django项目中srtting.py文件中的38行,APP
- 一、python读取excel表格数据1、读取excel表格数据常用操作import xlrd# 打开excel表格data_excel =
- Matplotlib是一个很好的作图软件,但是python下默认不支持中文,所以需要做一些修改,方法如下:1.在python安装目录的Lib
- 通过python与ffmpeg结合使用,可生成进行视频点播、直播的压力测试脚本。可支持不同类型的视频流,比如rtmp或者hls形式。 通过如
- 上次介绍了如何通过钉钉进行群通知,有同学反馈自己更习惯使用企业微信或公司使用了企业微信,希望也能出个基于Python的企业微信的群通知教程,
- 说明字符串驻留是一种仅保存一份相同且不可变字符串的方法。不同的值被存放在字符串驻留池中,发生驻留之后, 许多变量可能指向内存中的相同字符串对
- 在VBScript中,有一个On Error Resume Next语句,它使脚本解释器忽略运行期错误并继续脚本代码的执行。接着该脚本可以检
- div和span、relative和absolute、display和visibility是很容易混淆和弄错的HTML标签与CSS属性,简单