2016-06-28 80 views
8

我用單元測試法對我的Tensorflow代碼進行了單元測試,但它產生了如此多的冗長輸出,使得它無用。如何抑制詳細的Tensorflow日誌記錄?

下面的測試

import unittest 
import tensorflow as tf 

class MyTest(unittest.TestCase): 

    def test_creation(self): 
     self.assertEquals(True, False) 

nosetests運行造成了巨大的無用的記錄量:

FAIL: test_creation (tests.test_tf.MyTest) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/home/cebrian/GIT/thesis-nilm/code/deepmodels/tests/test_tf.py", line 10, in test_creation 
    self.assertEquals(True, False) 
AssertionError: True != False 
-------------------- >> begin captured logging << -------------------- 
tensorflow: Level 1: Registering Const (<function _ConstantShape at 0x7f4379131c80>) in shape functions. 
tensorflow: Level 1: Registering Assert (<function no_outputs at 0x7f43791319b0>) in shape functions. 
tensorflow: Level 1: Registering Print (<function _PrintGrad at 0x7f4378effd70>) in gradient. 
tensorflow: Level 1: Registering Print (<function unchanged_shape at 0x7f4379131320>) in shape functions. 
tensorflow: Level 1: Registering HistogramAccumulatorSummary (None) in gradient. 
tensorflow: Level 1: Registering HistogramSummary (None) in gradient. 
tensorflow: Level 1: Registering ImageSummary (None) in gradient. 
tensorflow: Level 1: Registering AudioSummary (None) in gradient. 
tensorflow: Level 1: Registering MergeSummary (None) in gradient. 
tensorflow: Level 1: Registering ScalarSummary (None) in gradient. 
tensorflow: Level 1: Registering ScalarSummary (<function _ScalarShape at 0x7f4378f042a8>) in shape functions. 
tensorflow: Level 1: Registering MergeSummary (<function _ScalarShape at 0x7f4378f042a8>) in shape functions. 
tensorflow: Level 1: Registering AudioSummary (<function _ScalarShape at 0x7f4378f042a8>) in shape functions. 
tensorflow: Level 1: Registering ImageSummary (<function _ScalarShape at 0x7f4378f042a8>) in shape functions. 
tensorflow: Level 1: Registering HistogramSummary (<function _ScalarShape at 0x7f4378f042a8>) in shape functions. 
tensorflow: Level 1: Registering HistogramAccumulatorSummary (<function _ScalarShape at 0x7f4378f042a8>) in shape functions. 
tensorflow: Level 1: Registering Pack (<function _PackShape at 0x7f4378f047d0>) in shape functions. 
tensorflow: Level 1: Registering Unpack (<function _UnpackShape at 0x7f4378f048c0>) in shape functions. 
tensorflow: Level 1: Registering Concat (<function _ConcatShape at 0x7f4378f04938>) in shape functions. 
tensorflow: Level 1: Registering ConcatOffset (<function _ConcatOffsetShape at 0x7f4378f049b0>) in shape functions. 

...... 

而使用tensorflow從IPython中控制檯似乎並不認爲冗長:

$ ipython 
Python 2.7.11+ (default, Apr 17 2016, 14:00:29) 
Type "copyright", "credits" or "license" for more information. 

IPython 4.2.0 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object', use 'object??' for extra details. 

In [1]: import tensorflow as tf 
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally 
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally 
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally 
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so locally 
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally 

In [2]: 

如何在運行時抑制以前的日誌記錄nosetests?

+0

的可能的複製[禁用Tensorflow調試信息(http://stackoverflow.com/questions/35911252/disable-tensorflow-debugging-information) – craymichael

+0

另一種解決方案:HTTPS: //stackoverflow.com/questions/43337601/nosetests-with-tensorflow-lots-of-debugging-output-how-to-disable – vpekar

回答

0

這裏是an example這樣做。不幸的是,這需要修改源和重建。這裏有一個tracking bug,使其更容易

18

1.0更新(17年5月20日):

在TensorFlow 1.0,每本issue,你現在可以控制通過所謂TF_CPP_MIN_LOG_LEVEL環境變量記錄;它默認爲0(所有日誌顯示),但可以設置爲1來過濾掉INFO日誌,2可以額外過濾出WARNING日誌,而3可以額外過濾掉ERROR日誌。使用Python參見下面的通用OS例如:

import os 
import tensorflow as tf 

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 

對於TensorFlow之前的版本或TF-學習日誌,看到以下內容:

查看下面有關TensorFlow記錄信息的頁面;使用新更新,您可以將日誌記錄詳細設置爲DEBUG,INFO,WARN,ERRORFATAL。例如:

tf.logging.set_verbosity(tf.logging.ERROR) 

該頁面另外還有一個可以與TF-Learn模型一起使用的監視器。 Here is the page

阻止所有日誌記錄,雖然(只TF-Learn)。我有兩個解決方案;一個是'技術上正確的'解決方案(Linux),另一個涉及重建TensorFlow。

script -c 'python [FILENAME].py' | grep -v 'I tensorflow/' 

對於其他,請參閱this answer這涉及修改源和重建TensorFlow。