在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 相关文章推荐
wxPython窗口的继承机制实例分析
Sep 28 Python
python使用MySQLdb访问mysql数据库的方法
Aug 03 Python
python基础学习之如何对元组各个元素进行命名详解
Jul 12 Python
在python中按照特定顺序访问字典的方法详解
Dec 14 Python
Python3之手动创建迭代器的实例代码
May 22 Python
postman传递当前时间戳实例详解
Sep 14 Python
python KNN算法实现鸢尾花数据集分类
Oct 24 Python
python接口自动化如何封装获取常量的类
Dec 24 Python
Python利用PyPDF2库获取PDF文件总页码实例
Apr 03 Python
Python图片处理模块PIL操作方法(pillow)
Apr 07 Python
PyTorch-GPU加速实例
Jun 23 Python
Django启动时找不到mysqlclient问题解决方案
Nov 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基于php_imagick_st-Q8.dll实现JPG合成GIF图片的方法
2014/07/11 PHP
理解PHP中的Session及对Session有效期的控制
2016/01/08 PHP
php 数组处理函数extract详解及实例代码
2016/11/23 PHP
PHP标准库(PHP SPL)详解
2019/03/16 PHP
Open and Print a Word Document
2007/06/15 Javascript
jquery创建div 实现代码
2009/04/27 Javascript
文件编码导致jquery失效的解决方法
2013/06/26 Javascript
jQuery插件开发详细教程
2014/06/06 Javascript
浅谈javascript面向对象程序设计
2015/01/21 Javascript
jquery实现上下左右滑动的方法
2015/02/09 Javascript
Javascript实现可旋转的圆圈实例代码
2015/08/04 Javascript
jQuery实现的网页右下角tab样式在线客服效果代码
2015/10/23 Javascript
浅谈jquery的map()和each()方法
2016/06/12 Javascript
Nodejs进阶:如何将图片转成datauri嵌入到网页中去实例
2016/11/21 NodeJs
关于Function中的bind()示例详解
2016/12/02 Javascript
基于vue的换肤功能的示例代码
2017/10/10 Javascript
jsonp跨域获取数据的基础教程
2018/07/01 Javascript
解决vue-cli 打包后自定义动画未执行的问题
2019/11/12 Javascript
[01:18:33]Secret vs VGJ.S Supermajor小组赛C组 BO3 第一场 6.3
2018/06/04 DOTA
仅用50行代码实现一个Python编写的计算器的教程
2015/04/17 Python
在cmd命令行里进入和退出Python程序的方法
2018/05/12 Python
学生信息管理系统python版
2018/10/17 Python
python3+opencv3识别图片中的物体并截取的方法
2018/12/05 Python
pytorch对可变长度序列的处理方法详解
2018/12/08 Python
单身旅行者的单身假期:Just You
2018/04/08 全球购物
西班牙三叶草药房:Farmacias Trébol
2019/05/03 全球购物
大学生咖啡店创业计划书
2014/01/21 职场文书
代收款委托书范本
2014/10/01 职场文书
离婚协议书怎样才有法律效力
2014/10/10 职场文书
学校计划生育责任书
2015/05/09 职场文书
社区党建工作总结2015
2015/05/13 职场文书
毕业论文答辩开场白和答辩技巧
2015/05/27 职场文书
篮球拉拉队口号
2015/12/25 职场文书
《火烧云》教学反思
2016/02/23 职场文书
bat批处理之字符串操作的实现
2022/03/16 Python
sqlserver连接错误之SQL评估期已过的问题解决
2022/03/23 SQL Server