How to suppress the ubiquitous Tensorflow magazine?

I clean my Tensorflow code with nosetests, but it produces so many detailed results that it makes it useless.

Next test

import unittest import tensorflow as tf class MyTest(unittest.TestCase): def test_creation(self): self.assertEquals(True, False) 

when started with nosetests creates a huge amount of useless logging:

 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. ...... 

whereas using tensorflow from the ipython console doesn't look so verbose:

 $ 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 features. %quickref -> Quick reference. help -> Python 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]: 

How can I suppress previous logging when running nosetests?

+16
source share
3 answers

Update 2.0 (08.10.19) Setting TF_CPP_MIN_LOG_LEVEL should still work (see update v0. 12+ below), but there is currently an open problem (see Issue # 31870 ). If the TF_CPP_MIN_LOG_LEVEL setting TF_CPP_MIN_LOG_LEVEL not work for you (again, see below), try the following to set the log level:

 import tensorflow as tf tf.get_logger().setLevel('INFO') 

In addition, see the documentation for tf.autograph.set_verbosity for details on autograph log messages, for example:

 # Can also be set using the AUTOGRAPH_VERBOSITY environment variable tf.autograph.set_verbosity(1) 

v0. 12+ Update (05/20/17), work through TF 2. 0+:

In TensorFlow 0. 12+, for this problem , now you can control the registration through an environment variable called TF_CPP_MIN_LOG_LEVEL ; by default it is 0 (all logs are shown), but one of the following values ​​in the Level column can be set.

  Level | Level for Humans | Level Description -------|------------------|------------------------------------ 0 | DEBUG | [Default] Print all messages 1 | INFO | Filter out INFO messages 2 | WARNING | Filter out INFO & WARNING messages 3 | ERROR | Filter out all messages 

See the following general OS example using Python:

 import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # or any {'0', '1', '2'} import tensorflow as tf 

To be precise, you can also set the level for the Python tf_logging module, which is used, for example, in. summary operations, tensor board, various ratings, etc.

 # append to lines above tf.logging.set_verbosity(tf.logging.ERROR) # or any {DEBUG, INFO, WARN, ERROR, FATAL} 

For version 1.14, you will receive warnings if you do not switch to using API v1 as follows:

 # append to lines above tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) # or any {DEBUG, INFO, WARN, ERROR, FATAL} 


For previous versions of TensorFlow or TF-Learn Logging (v0.11.x or lower):

See the page below for information on logging TensorFlow; with the new update, you can set the logging details to DEBUG , INFO , WARN , ERROR or FATAL . For instance:

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

The page also displays monitors that can be used with TF-Learn models. Here is the page .

This does not block all logs (TF-Learn only). I have two solutions; one is the “technically correct” solution (Linux), and the other is a rebuild of TensorFlow.

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

For reading, see this answer , which includes changing the source code and rebuilding TensorFlow.

+29
source

Running tests using nosetests --nologcapture will disable the display of these logs. Additional registration information for media: https://nose.readthedocs.io/en/latest/plugins/logcapture.html

+9
source

Here is an example of this. Unfortunately, this requires a change in source and recovery. Here's a tracking bug to simplify it

0
source

Source: https://habr.com/ru/post/1273688/


All Articles