在tensorflow中實(shí)現(xiàn)屏蔽輸出的log信息
tensorflow中可以通過(guò)配置環(huán)境變量 'TF_CPP_MIN_LOG_LEVEL' 的值,控制tensorflow是否屏蔽通知信息、警告、報(bào)錯(cuò)等輸出信息。
使用方法:
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也是默認(rèn)值,輸出所有信息
TF_CPP_MIN_LOG_LEVEL 取值 1 : 屏蔽通知信息
TF_CPP_MIN_LOG_LEVEL 取值 2 : 屏蔽通知信息和警告信息
TF_CPP_MIN_LOG_LEVEL 取值 3 : 屏蔽通知信息、警告信息和報(bào)錯(cuò)信息
測(cè)試代碼:
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也是默認(rèn)的輸出,分為三部分,一個(gè)是警告信息說(shuō)沒(méi)有優(yōu)化加速,二是通知信息告知操作所用的設(shè)備,三是程序中代碼指定要輸出的結(jié)果信息
TF_CPP_MIN_LOG_LEVEL 為 1 的輸出,沒(méi)有通知信息了: 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 的輸出,設(shè)置為2就沒(méi)有警告信息了,設(shè)置為3警告和報(bào)錯(cuò)信息(如果有)就都沒(méi)有了:
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中實(shí)現(xiàn)屏蔽輸出的log信息就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python中bytes和str的區(qū)別與聯(lián)系詳解
Python3最重要的新特性之一是對(duì)字符串和二進(jìn)制數(shù)據(jù)流做了明確的區(qū),下面這篇文章主要給大家介紹了關(guān)于Python中bytes和str區(qū)別與聯(lián)系的相關(guān)資料,需要的朋友可以參考下2022-05-05
python數(shù)據(jù)類型的詳細(xì)分析(附示例代碼)
這篇文章主要給大家介紹了關(guān)于python數(shù)據(jù)類型分析的相關(guān)資料,python里可以通過(guò)type()函數(shù)來(lái)查看數(shù)據(jù)類型,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-09-09
python按列索引提取文件夾內(nèi)所有excel指定列匯總(示例代碼)
這篇文章主要介紹了python按列索引提取文件夾內(nèi)所有excel指定列匯總,本文通過(guò)多種場(chǎng)景分析結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03
Python腳本/代碼的幾種常見(jiàn)運(yùn)行方式
我們知道,python腳本或者說(shuō)python程序其實(shí)是一個(gè)包含了python代碼的文件,通過(guò)運(yùn)行python代碼,我們可以驗(yàn)證腳本/程序是否按照我們的期望執(zhí)行,在python中,有多種方式來(lái)運(yùn)行腳本或程序,取決于小伙伴們的需求,接下來(lái)小編將介紹幾種常見(jiàn)的 python 代碼運(yùn)行方式2023-10-10
python3.6環(huán)境下安裝freetype庫(kù)和基本使用方法(推薦)
這篇文章主要介紹了python3.6環(huán)境下如何安裝freetype庫(kù)和基本使用方法,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05
Python DataFrame實(shí)現(xiàn)固定周期內(nèi)統(tǒng)計(jì)每列的非零值
在數(shù)據(jù)處理中,使用DataFrame統(tǒng)計(jì)固定周期內(nèi)每列的非零值數(shù)量是一種常見(jiàn)需求,通過(guò)將數(shù)據(jù)分組并使用計(jì)數(shù)函數(shù),可以方便地實(shí)現(xiàn)此目標(biāo),具體方法包括首先計(jì)算每列的0值個(gè)數(shù),然后通過(guò)總數(shù)減去0值個(gè)數(shù)得到非零值的數(shù)量2024-09-09
PyTorch手寫數(shù)字?jǐn)?shù)據(jù)集進(jìn)行多分類
這篇文章主要介紹了PyTorch手寫數(shù)字?jǐn)?shù)據(jù)集進(jìn)行多分類,損失函數(shù)采用交叉熵,激活函數(shù)采用ReLU,優(yōu)化器采用帶有動(dòng)量的mini-batchSGD算法,需要的朋友可以參考一下2022-03-03

