在tensorflow中实现屏蔽输出的log信息


Posted in Python onFebruary 04, 2020

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.]

以上这篇在tensorflow中实现屏蔽输出的log信息就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python逐行读取文件内容的三种方法
Jan 20 Python
在Python中使用SimpleParse模块进行解析的教程
Apr 11 Python
Django验证码的生成与使用示例
May 20 Python
多个应用共存的Django配置方法
May 30 Python
对python字典过滤条件的实例详解
Jan 22 Python
解决.ui文件生成的.py文件运行不出现界面的方法
Jun 19 Python
python设置随机种子实例讲解
Sep 12 Python
Pytorch DataLoader 变长数据处理方式
Jan 08 Python
Python argparse模块使用方法解析
Feb 20 Python
基于Python数据结构之递归与回溯搜索
Feb 26 Python
Python生成器常见问题及解决方案
Mar 21 Python
python opencv把一张图片嵌入(叠加)到另一张图片上的实现代码
Jun 11 Python
Python变量作用域LEGB用法解析
Feb 04 #Python
如何在python开发工具PyCharm中搭建QtPy环境(教程详解)
Feb 04 #Python
TensorFlow基本的常量、变量和运算操作详解
Feb 03 #Python
Tensorflow轻松实现XOR运算的方式
Feb 03 #Python
Tensorflow不支持AVX2指令集的解决方法
Feb 03 #Python
基于Python3.6中的OpenCV实现图片色彩空间的转换
Feb 03 #Python
解决Tensorflow 使用时cpu编译不支持警告的问题
Feb 03 #Python
You might like
php+js实现图片的上传、裁剪、预览、提交示例
2013/08/27 PHP
Yii中srbac权限扩展模块工作原理与用法分析
2016/07/14 PHP
laravel 解决路由除了根目录其他都404的问题
2019/10/18 PHP
PHP调用QQ互联接口实现QQ登录网站功能示例
2019/10/24 PHP
jQuery图片的展开和收缩实现代码
2013/04/16 Javascript
深入理解javascript动态插入技术
2013/11/12 Javascript
利用JavaScript检测CPU使用率自己写的
2014/03/22 Javascript
JavaScript中Date.toSource()方法的使用教程
2015/06/12 Javascript
基于jquery实现的树形菜单效果代码
2015/09/06 Javascript
JSON字符串和对象相互转换实例分析
2016/06/16 Javascript
学习Javascript闭包(Closure)知识
2016/08/07 Javascript
AngularJS 自定义指令详解及示例代码
2016/08/17 Javascript
js图片切换具体实现代码
2016/10/13 Javascript
使用Promise链式调用解决多个异步回调的问题
2017/01/15 Javascript
在vue中使用echars实现上浮与下钻效果
2019/11/08 Javascript
Python写的Tkinter程序屏幕居中方法
2015/03/10 Python
Python基于scrapy采集数据时使用代理服务器的方法
2015/04/16 Python
python模拟事件触发机制详解
2018/01/19 Python
多个应用共存的Django配置方法
2018/05/30 Python
tensorflow: 查看 tensor详细数值方法
2018/06/13 Python
python安装pywin32clipboard的操作方法
2019/01/24 Python
python下载微信公众号相关文章
2019/02/26 Python
python利用re,bs4,requests模块获取股票数据
2019/07/29 Python
Python3批量移动指定文件到指定文件夹方法示例
2019/09/02 Python
Python上下文管理器用法及实例解析
2019/11/11 Python
浅谈Django中的QueryDict元素为数组的坑
2020/03/31 Python
关于解决iframe标签嵌套问题的解决方法
2020/03/04 HTML / CSS
护士岗位求职应聘自荐书范文
2014/02/12 职场文书
期终自我鉴定
2014/02/17 职场文书
岗位职责说明书
2014/05/07 职场文书
奥林匹克的口号
2014/06/13 职场文书
政风行风评议整改方案
2014/09/15 职场文书
教师党员批评与自我批评
2014/10/15 职场文书
老公写给老婆的检讨书
2015/05/06 职场文书
《揠苗助长》教学反思
2016/02/20 职场文书
简单聊聊Golang中defer预计算参数
2022/03/25 Golang