在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文件夹与文件的操作实现代码
Jul 13 Python
Python中使用第三方库xlutils来追加写入Excel文件示例
Apr 05 Python
Python基于smtplib实现异步发送邮件服务
May 28 Python
Python正则表达式如何进行字符串替换实例
Dec 28 Python
Anaconda 离线安装 python 包的操作方法
Jun 11 Python
python用plt画图时,cmp设置方法
Dec 13 Python
python文件选择对话框的操作方法
Jun 27 Python
python里运用私有属性和方法总结
Jul 08 Python
numpy.random.shuffle打乱顺序函数的实现
Sep 10 Python
Python使用Turtle库绘制一棵西兰花
Nov 23 Python
Python selenium的基本使用方法分析
Dec 21 Python
用python3读取python2的pickle数据方式
Dec 25 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解析html的实现代码
2011/08/08 PHP
thinkphp实现163、QQ邮箱收发邮件的方法
2015/12/18 PHP
关于ThinkPhp 框架表单验证及ajax验证问题
2017/07/19 PHP
PHP抽象类和接口用法实例详解
2019/07/20 PHP
yepnope.js 异步加载资源文件
2011/09/08 Javascript
jquery ajax jsonp跨域调用实例代码
2013/12/11 Javascript
node.js中的buffer.slice方法使用说明
2014/12/10 Javascript
javascript 实现 原路返回
2015/01/21 Javascript
js图片轮播效果实现代码
2020/04/18 Javascript
js+html5实现的自由落体运动效果代码
2016/01/28 Javascript
Bootstrap select下拉联动(jQuery cxselect)
2017/01/04 Javascript
Bootstrap多级菜单的实现代码
2017/05/23 Javascript
bootstrap插件treeview实现全选父节点下所有子节点和反选功能
2017/07/21 Javascript
react-native中ListView组件点击跳转的方法示例
2017/09/30 Javascript
微信小程序实现富文本图片宽度自适应的方法
2019/01/20 Javascript
vscode vue 文件模板的配置方法
2019/07/23 Javascript
低版本中Python除法运算小技巧
2015/04/05 Python
Python中的推导式使用详解
2015/06/03 Python
基于Python Shell获取hostname和fqdn释疑
2016/01/25 Python
Python实现Windows和Linux之间互相传输文件(文件夹)的方法
2017/05/08 Python
Python中字典的浅拷贝与深拷贝用法实例分析
2018/01/02 Python
基于Python中求和函数sum的用法详解
2018/06/28 Python
Python3自动签到 定时任务 判断节假日的实例
2018/11/13 Python
python 函数内部修改外部变量的方法
2018/12/18 Python
python调用staf自动化框架的方法
2018/12/26 Python
详解python中的生成器、迭代器、闭包、装饰器
2019/08/22 Python
在python Numpy中求向量和矩阵的范数实例
2019/08/26 Python
pytorch进行上采样的种类实例
2020/02/18 Python
基于Python的身份证验证识别和数据处理详解
2020/11/14 Python
真正了解CSS3背景下的@font face规则
2017/05/04 HTML / CSS
CSS3中几个新增加的盒模型属性使用教程
2016/03/01 HTML / CSS
试用期转正鉴定评语
2014/01/27 职场文书
小学五年级班主任工作经验交流材料
2015/11/02 职场文书
中职班主任培训心得体会
2016/01/07 职场文书
python神经网络编程之手写数字识别
2021/05/08 Python
Spring Boot项目如何优雅实现Excel导入与导出功能
2022/06/10 Java/Android