在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使用rabbitmq实现网络爬虫示例
Feb 20 Python
python数组过滤实现方法
Jul 27 Python
Python实现按学生年龄排序的实际问题详解
Aug 29 Python
深入理解Django中内置的用户认证
Oct 06 Python
Python实现针对给定字符串寻找最长非重复子串的方法
Apr 21 Python
使用Python快速搭建HTTP服务和文件共享服务的实例讲解
Jun 04 Python
Python3 SSH远程连接服务器的方法示例
Dec 29 Python
Python mutiprocessing多线程池pool操作示例
Jan 30 Python
使用Python制作缩放自如的圣诞老人(圣诞树)
Dec 25 Python
python 给图像添加透明度(alpha通道)
Apr 09 Python
python 实现波浪滤镜特效
Dec 02 Python
python pandas 解析(读取、写入)CSV 文件的操作方法
Dec 24 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初学者常见问题集合 修正版(21问答)
2010/03/23 PHP
PHP类的静态(static)方法和静态(static)变量使用介绍
2012/02/19 PHP
yii上传文件或图片实例
2014/04/01 PHP
用于table内容排序
2006/07/21 Javascript
jQuery 开天辟地入门篇一
2009/12/09 Javascript
Jquery+WebService 校验账号是否已被注册的代码
2010/07/12 Javascript
为jQuery.Treeview添加右键菜单的实现代码
2010/10/22 Javascript
js中更短的 Array 类型转换
2011/10/30 Javascript
javascript SpiderMonkey中的函数序列化如何进行
2012/12/05 Javascript
jquery 文本上下无缝滚动,鼠标放上去就停止 小例子
2013/06/05 Javascript
Javascript控制页面链接在新窗口打开具体方法
2013/08/16 Javascript
jQuery页面加载初始化常用的三种方法
2014/06/04 Javascript
超链接的禁用属性Disabled使用示例
2014/07/31 Javascript
JavaScript学习笔记之Cookie对象
2015/01/22 Javascript
jquery中EasyUI使用技巧小结
2015/02/10 Javascript
es6中使用map简化复杂条件判断操作实例详解
2020/02/19 Javascript
python数据结构之二叉树的遍历实例
2014/04/29 Python
Python实现Mysql数据库连接池实例详解
2017/04/11 Python
使用Python和xlwt向Excel文件中写入中文的实例
2018/04/21 Python
python实现字符串加密 生成唯一固定长度字符串
2019/03/22 Python
详解Matplotlib绘图之属性设置
2019/08/23 Python
自定义Django Form中choicefield下拉菜单选取数据库内容实例
2020/03/13 Python
Python startswith()和endswith() 方法原理解析
2020/04/28 Python
Python实现清理微信僵尸粉功能示例【基于itchat模块】
2020/05/29 Python
python和JavaScript哪个容易上手
2020/06/23 Python
Python绘图之柱形图绘制详解
2020/07/28 Python
python中翻译功能translate模块实现方法
2020/12/17 Python
解决Python import .pyd 可能遇到路径的问题
2021/03/04 Python
DC Shoes荷兰官方网站:美国极限运动品牌
2019/10/22 全球购物
机关单位动员会主持词
2014/03/20 职场文书
学位证书委托书
2014/09/30 职场文书
博士生专家推荐信
2015/03/25 职场文书
公司副总经理岗位职责
2015/04/08 职场文书
2015年教师党员承诺书
2015/04/27 职场文书
2016年记者节感言
2015/12/08 职场文书
日元符号 ¥
2022/02/17 杂记