在tensorflow中实现屏蔽输出的log信息
作者:-牧野- 发布时间:2023-02-27 17:41:21
标签:tensorflow,屏蔽,输出,log
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.]
来源:https://blog.csdn.net/dcrmg/article/details/80029741


猜你喜欢
- rhel5下默认安装mysql5.0后,中文显示为乱码原因:mysql默认字符集是latin,所以中文不能正常显示解决方法:修改配置文件,
- 问题描述:某天使用idea,突然发现git提交记录没法查看具体提交的文件了。只能看到提交记录,如下图:分析可能是修改了控件设置的原因,于是尝
- 本文用python写了一个会员管理系统,供大家参考,具体内容如下:"""后台管理员前台会员信息系统1.后台管理
- 使用ASP处理XSLT转换XML比较简单,思路如下:创建一个XSLTemplate的对象,再创建一个XMLDOM对象,然后在家Xml文件和X
- 本文实例讲述了PHP Static延迟静态绑定用法。分享给大家供大家参考,具体如下:PHP5.3以后引入了延迟静态绑定static,它是为了
- 一个简单的for语句就能循环字典的所有键,就像处理序列一样:In [1]: d = {'x':1, 'y':
- 5月3日晚,央视在《新闻联播》前播放了B站青年宣言片《后浪》,这是B站首次登陆央视黄金时段,今天在朋友圈陆续看到相关的视频。最早用B站的同学
- 问题最近在做项目的时候, dialog组件回调close里面 一般我都会加个resetFields 重置初始值和校验其他地方都没问题, 在t
- 前言:在软件测试中,为项目编写接口自动化用例已成为测试人员常驻的测试工作。本文以python为例,基于笔者曾使用过的三种用例数据读取方法:x
- 这篇文章主要介绍了如何基于Python实现自动扫雷,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可
- 需求我在最近的一个任务中,存在一个redis高并发计算多个客户端接收预警信息的时长问题。模型是首先模拟多个客户端连接预警服务器集群,然后向预
- 如何分析程序运行所需时间及cpu的使用率?使用shell内置的time指令最常见的方式便是linux中内置的time指令,通过time go
- 点击顶部的“SQL”标签进入sql命令输入界面。输入以下命令:update mysql.user set password=PASSWORD
- 为什么我把自己机子上的数据库备份文件往另一台机子上还原不成功?可能是你在Restore的对话框中选项不正确。Restore 有三个选项,分别
- 要解决两个需求: 一个是从A页面跳到B页面,滚动到页面的任何地方; 第二个是在B页面内部点击某个元素,滚动到页面的任何地方; 怎么解决啊?很
- 首先,你需要去有道翻译API官网去申请key:http://fanyi.youdao.com/openapi?path=data-mode得
- 这两副图片哪张更能勾起你买东西的欲望呢?相信大多数买家更喜欢看大图,实物图,产品细节图等.如果我们的卖家更能倾听下我们买家的心声.他们的产品
- 本文实例讲述了PHP实现绘制二叉树图形显示功能。分享给大家供大家参考,具体如下:前言:最近老师布置了一个作业:理解并实现平衡二叉树和红黑树,
- 1.展开服务器对象-->链接服务器-->右击"新建链接服务器"注意:必须以数据库管理员身份登录(通常也就是s
- 本文实例为大家分享了js实现简单放大镜效果的具体代码,供大家参考,具体内容如下效果效果,鼠标在原图片移动,黄色小盒子跟随鼠标移动,黄色小盒子