在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 相关文章推荐
Fiddler如何抓取手机APP数据包
Jan 22 Python
python安装与使用redis的方法
Apr 19 Python
python实现隐马尔科夫模型HMM
Mar 25 Python
Python实现检测文件MD5值的方法示例
Apr 11 Python
python读取txt文件,去掉空格计算每行长度的方法
Dec 20 Python
对python中list的拷贝与numpy的array的拷贝详解
Jan 29 Python
python 爬虫百度地图的信息界面的实现方法
Oct 27 Python
python找出列表中大于某个阈值的数据段示例
Nov 24 Python
解决python中的幂函数、指数函数问题
Nov 25 Python
学会python自动收发邮件 代替你问候女友
May 20 Python
Python self用法详解
Nov 28 Python
python lambda的使用详解
Feb 26 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 处理上百万条的数据库如何提高处理查询速度
2010/02/08 PHP
php计算两个日期相差天数的方法
2015/03/14 PHP
PHP生成随机字符串(3种方法)
2015/09/25 PHP
php array_pop 删除数组最后一个元素实例
2016/11/02 PHP
JS的数组迭代方法
2015/02/05 Javascript
浅谈JavaScript的事件
2015/02/27 Javascript
纯javascript实现简单下拉刷新功能
2015/03/13 Javascript
SpringMVC框架下JQuery传递并解析Json格式的数据是如何实现的
2015/12/10 Javascript
Zero Clipboard实现浏览器复制到剪贴板的方法(多个复制按钮)
2016/03/24 Javascript
基于BootStrap Metronic开发框架经验小结【五】Bootstrap File Input文件上传插件的用法详解
2016/05/12 Javascript
基于vue的下拉刷新指令和滚动刷新指令
2016/12/23 Javascript
AngularJS 使用ng-repeat报错 [ngRepeat:dupes]
2017/01/19 Javascript
使用vue.js2.0 + ElementUI开发后台管理系统详细教程(一)
2017/01/21 Javascript
微信小程序-获得用户输入内容
2017/02/13 Javascript
requirejs + vue 项目搭建详解
2017/06/16 Javascript
vue的keep-alive中使用EventBus的方法
2019/04/23 Javascript
python连接mysql调用存储过程示例
2014/03/05 Python
Python实现的自定义多线程多进程类示例
2018/03/23 Python
python对list中的每个元素进行某种操作的方法
2018/06/29 Python
对python中if语句的真假判断实例详解
2019/02/18 Python
python文件和文件夹复制函数
2020/02/07 Python
解决使用python print打印函数返回值多一个None的问题
2020/04/09 Python
python3通过qq邮箱发送邮件以及附件
2020/05/20 Python
Keras 切换后端方式(Theano和TensorFlow)
2020/06/19 Python
html5实现完美兼容各大浏览器的播放器
2014/12/26 HTML / CSS
StudentUniverse英国:学生航班、酒店和旅游
2019/08/25 全球购物
汽车技术服务英文求职信范文
2014/01/02 职场文书
大学生素质拓展活动方案
2014/02/11 职场文书
高中教师个人总结
2015/02/10 职场文书
二审答辩状范文
2015/05/22 职场文书
小组口号霸气押韵
2015/12/24 职场文书
HTML中的表单Form实现居中效果
2021/05/25 HTML / CSS
pytorch 如何使用batch训练lstm网络
2021/05/28 Python
python中如何对多变量连续赋值
2021/06/03 Python
SpringBoot快速入门详解
2021/07/21 Java/Android
windows server2012 R2下安装PaddleOCR服务的的详细步骤
2022/09/23 Servers