在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 04 Python
python 实现tar文件压缩解压的实例详解
Aug 20 Python
python的变量与赋值详细分析
Nov 08 Python
Python抓取聚划算商品分析页面获取商品信息并以XML格式保存到本地
Feb 23 Python
解决pycharm无法识别本地site-packages的问题
Oct 13 Python
pandas中apply和transform方法的性能比较及区别介绍
Oct 30 Python
Python实现的特征提取操作示例
Dec 03 Python
python防止随意修改类属性的实现方法
Aug 21 Python
python实现梯度下降法
Mar 24 Python
如何理解python面向对象编程
Jun 01 Python
Python同时处理多个异常的方法
Jul 28 Python
Python 解析xml文件的示例
Sep 29 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设计模式 注册表模式(多个类的注册)
2012/02/05 PHP
用Simple Excel导出xls实现方法
2012/12/06 PHP
PHP实现的蚂蚁爬杆路径算法代码
2015/12/03 PHP
PHP实现图片的等比缩放和Logo水印功能示例
2017/05/04 PHP
jquery学习笔记二 实现可编辑的表格
2010/04/09 Javascript
url 编码 js url传参中文乱码解决方案
2010/04/11 Javascript
JQuery循环滚动图片代码
2011/12/08 Javascript
JavaScript设计模式之外观模式实例
2014/10/10 Javascript
JavaScript字符串对象replace方法实例(用于字符串替换或正则替换)
2014/10/16 Javascript
Javascript window对象详解
2014/11/12 Javascript
jquery.gridrotator实现响应式图片展示画廊效果
2015/06/23 Javascript
IE10中flexigrid无法显示数据的解决方法
2015/07/26 Javascript
JS字符串false转boolean的方法(推荐)
2017/03/08 Javascript
Vue2.0利用 v-model 实现组件props双向绑定的优美解决方案
2017/03/13 Javascript
妙用Angularjs实现表格按指定列排序
2017/06/23 Javascript
在Vuex使用dispatch和commit来调用mutations的区别详解
2018/09/18 Javascript
vue中slot(插槽)的介绍与使用
2018/11/12 Javascript
Vue的H5页面唤起支付宝支付功能
2019/04/18 Javascript
基于vue、react实现倒计时效果
2019/08/26 Javascript
Python学习pygal绘制线图代码分享
2017/12/09 Python
python+selenium识别验证码并登录的示例代码
2017/12/21 Python
Python解析json代码实例解析
2019/11/25 Python
基于Python数据结构之递归与回溯搜索
2020/02/26 Python
浅谈Python中的异常和JSON读写数据的实现
2020/02/27 Python
python脚本实现mp4中的音频提取并保存在原目录
2020/02/27 Python
python GUI库图形界面开发之PyQt5下拉列表框控件QComboBox详细使用方法与实例
2020/02/27 Python
Python3爬虫里关于识别微博宫格验证码的知识点详解
2020/07/30 Python
6种非常炫酷的CSS3按钮边框动画特效
2016/03/16 HTML / CSS
土耳其新趋势女装购物网站:Addax
2020/01/07 全球购物
个人承诺书
2014/03/26 职场文书
图书室标语
2014/06/21 职场文书
计划生育标语
2014/06/23 职场文书
人事专员岗位职责说明书
2014/07/30 职场文书
机修车间主任岗位职责
2015/04/08 职场文书
党风廉政建设心得体会(2016最新版)
2016/01/22 职场文书
小学美术教学反思
2016/02/17 职场文书