在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连接池实现示例程序
Nov 26 Python
Linux系统上Nginx+Python的web.py与Django框架环境
Dec 25 Python
Python实现字符串匹配算法代码示例
Dec 05 Python
Python3.6笔记之将程序运行结果输出到文件的方法
Apr 22 Python
对python3 Serial 串口助手的接收读取数据方法详解
Jun 12 Python
详解python pandas 分组统计的方法
Jul 30 Python
python学生信息管理系统实现代码
Dec 17 Python
Tensorflow中的降维函数tf.reduce_*使用总结
Apr 20 Python
Python urllib3软件包的使用说明
Nov 18 Python
Python读取ini配置文件传参的简单示例
Jan 05 Python
Pygame Time时间控制的具体使用详解
Nov 17 Python
实战Python爬虫爬取酷我音乐
Apr 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 adodb分页实现代码
2009/03/19 PHP
php 获取SWF动画截图示例代码
2014/02/10 PHP
PHP基于curl post实现发送url及相关中文乱码问题解决方法
2017/11/25 PHP
JS复制到剪贴板示例代码
2013/10/30 Javascript
点击表单提交时出现jQuery没有权限的解决方法
2014/07/23 Javascript
jQuery中常用动画效果函数(日常整理)
2016/09/17 Javascript
浅谈Javascript中的Label语句
2016/12/14 Javascript
jQuery实现的无缝广告图片左右滚动功能详解
2016/12/24 Javascript
如何在AngularJs中调用第三方插件库
2017/05/21 Javascript
seaJs使用心得之exports与module.exports的区别实例分析
2017/10/13 Javascript
详解vue-cli脚手架中webpack配置方法
2018/08/22 Javascript
vue无限轮播插件代码实例
2019/05/10 Javascript
layui 实现二级弹窗弹出之后 关闭一级弹窗的方法
2019/09/18 Javascript
javascript使用Blob对象实现的下载文件操作示例
2020/04/18 Javascript
在Python中操作文件之read()方法的使用教程
2015/05/24 Python
Python函数的周期性执行实现方法
2016/08/13 Python
详解使用python的logging模块在stdout输出的两种方法
2017/05/17 Python
[原创]使用豆瓣提供的国内pypi源
2017/07/02 Python
matplotlib绘制动画代码示例
2018/01/02 Python
使用python实现链表操作
2018/01/26 Python
python 执行终端/控制台命令的例子
2019/07/12 Python
Python 实现大整数乘法算法的示例代码
2019/09/17 Python
pycharm修改file type方式
2019/11/19 Python
python如何实现不可变字典inmutabledict
2020/01/08 Python
pyqt5数据库使用详细教程(打包解决方案)
2020/03/25 Python
香港草莓网土耳其网站:Strawberrynet TR
2017/03/02 全球购物
美国CVS药店官网:CVS Pharmacy
2018/07/26 全球购物
美国电子产品主要品牌的授权在线零售商:DataVision
2019/03/23 全球购物
英国领先的在线鱼贩:The Fish Society
2020/08/12 全球购物
英文版销售经理个人求职信
2013/11/20 职场文书
学习十八大精神心得体会
2013/12/31 职场文书
食堂采购员岗位职责
2014/03/17 职场文书
民主评议政风行风整改方案
2014/09/17 职场文书
企业工会工作总结2015
2015/05/13 职场文书
火烧圆明园的观后感
2015/06/03 职场文书
Three.js实现雪糕地球的使用示例详解
2022/07/07 Javascript