在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基础入门学习笔记(Python环境搭建)
Jan 13 Python
轻松实现TensorFlow微信跳一跳的AI
Jan 05 Python
Python编程二分法实现冒泡算法+快速排序代码示例
Jan 15 Python
Python实现的NN神经网络算法完整示例
Jun 19 Python
python获取当前文件路径以及父文件路径的方法
Jul 10 Python
对Django的restful用法详解(自带的增删改查)
Aug 28 Python
python输入错误后删除的方法
Oct 12 Python
python GUI库图形界面开发之PyQt5树形结构控件QTreeWidget详细使用方法与实例
Mar 02 Python
pyinstaller打包单文件时--uac-admin选项不起作用怎么办
Apr 15 Python
通过Python扫描代码关键字并进行预警的实现方法
May 24 Python
Python爬虫实现HTTP网络请求多种实现方式
Jun 19 Python
详解Open Folder as PyCharm Project怎么添加的方法
Dec 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数组函数序列之array_unique() - 去除数组中重复的元素值
2011/10/29 PHP
容易被忽略的JS脚本特性
2011/09/13 Javascript
JQuery入门——移除绑定事件unbind方法概述及应用
2013/02/05 Javascript
jquery获取焦点和失去焦点事件代码
2013/04/21 Javascript
JavaScript生成GUID的多种算法小结
2013/08/18 Javascript
JavaScript/Js脚本处理html元素的自定义属性解析(亲测兼容Firefox与IE)
2013/11/25 Javascript
Javascript排序算法之计数排序的实例
2014/04/05 Javascript
jquery实现简单的自动播放幻灯片效果
2015/06/13 Javascript
AngularJS 单元测试(一)详解
2016/09/21 Javascript
jquery延迟对象解析
2016/10/26 Javascript
js实现模糊匹配功能
2017/02/15 Javascript
jquery加载单文件vue组件的方法
2017/06/20 jQuery
NodeJs中express框架的send()方法简介
2017/06/20 NodeJs
nodejs连接mysql数据库及基本知识点详解
2018/03/20 NodeJs
JavaScript callback回调函数用法实例分析
2018/05/08 Javascript
详解Vue.js v-for不支持IE9的解决方法
2018/12/29 Javascript
详解js根据百度地图提供经纬度计算两点距离
2019/05/13 Javascript
JS实现网页时钟特效
2020/03/25 Javascript
小程序分享链接onShareAppMessage的具体用法
2020/05/22 Javascript
javascript实现一款好看的秒表计时器
2020/09/05 Javascript
解决pip install的时候报错timed out的问题
2018/06/12 Python
Django框架实现的简单分页功能示例
2018/12/04 Python
Python3.5字符串常用操作实例详解
2019/05/01 Python
Python流行ORM框架sqlalchemy安装与使用教程
2019/06/04 Python
python两种获取剪贴板内容的方法
2020/11/06 Python
10分钟理解CSS3 Grid布局
2018/12/20 HTML / CSS
美国领先的医疗警报服务:Philips Lifeline
2018/03/12 全球购物
销售副总经理岗位职责
2013/12/11 职场文书
即将毕业大学生自荐信
2014/01/24 职场文书
委托书范本
2014/04/02 职场文书
党员学习群众路线教育实践活动对照检查材料
2014/09/23 职场文书
乡镇法制宣传日活动总结
2015/05/05 职场文书
2015年幼儿园德育工作总结
2015/05/25 职场文书
小兵张嘎观后感300字
2015/06/03 职场文书
新员工实习期个人工作总结
2015/10/15 职场文书
使用CSS实现百叶窗效果示例代码
2023/05/07 HTML / CSS