Disable Tensorflow Debugging Information

By debugging information, I mean what TensorFlow shows in my terminal about loaded libraries and found devices, etc., and not Python errors.

I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcuda.so.1 locally I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:900] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: name: Graphics Device major: 5 minor: 2 memoryClockRate (GHz) 1.0885 pciBusID 0000:04:00.0 Total memory: 12.00GiB Free memory: 11.83GiB I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0: YI tensorflow/core/common_runtime/gpu/gpu_device.cc:717] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Graphics Device, pci bus id: 0000:04:00.0) I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 1.0KiB ... 
+125
python tensorflow
Mar 10 '16 at 8:32
source share
9 answers

You can disable all debug logs using os.environ :

 import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' import tensorflow as tf 

Tested on tf 0.12 and 1.0

In detail

 0 = all messages are logged (default behavior) 1 = INFO messages are not printed 2 = INFO and WARNING messages are not printed 3 = INFO, WARNING, and ERROR messages are not printed 
+153
Feb 08 '17 at 19:23
source share

v0. 12+ Update (05/20/17), Work through TF 2.0 alpha:

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 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 example:

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

+85
Jul 28 '16 at 19:33
source share

I also had this problem (on tensorflow-0.10.0rc0 ), but I could not fix the problem of registering excessive nose logs with the suggested answers.

I managed to solve this by probing directly into the tensor flow recorder. Not the most correct of the corrections, but it works fine and only pollutes test files that directly or indirectly import shadoworflow:

 # Place this before directly or indirectly importing tensorflow import logging logging.getLogger("tensorflow").setLevel(logging.WARNING) 
+13
Sep 26 '16 at 17:04 on
source share

For compatibility with Tensorflow 2.0 you can use tf.get_logger

 import logging tf.get_logger().setLevel(logging.ERROR) 
+11
Mar 13 '19 at 12:35
source share

Since TF_CPP_MIN_LOG_LEVEL does not work for me, you can try:

 tf.logging.set_verbosity(tf.logging.WARN) 

It worked for me in tenorflow v1.6.0

+10
Jul 13 '18 at 14:38
source share

The usual python3 log manager works with tenorflow == 1.11.0 for me:

 import logging logging.getLogger('tensorflow').setLevel(logging.INFO) 
+6
Oct 24 '18 at 16:12
source share

To add some flexibility here, you can achieve more granular control over the level of logging by writing a function that filters messages as you like:

 logging.getLogger('tensorflow').addFilter(my_filter_func) 

where my_filter_func takes a LogRecord object as input [ LogRecord docs ] and returns zero if you want the message to be thrown; nonzero otherwise.

Here is an example of a filter that only stores every nth informational message (Python 3 due to the use of nonlocal here):

 def keep_every_nth_info(n): i = -1 def filter_record(record): nonlocal i i += 1 return int(record.levelname != 'INFO' or i % n == 0) return filter_record # Example usage for TensorFlow: logging.getLogger('tensorflow').addFilter(keep_every_nth_info(5)) 

All of the above suggests that TensorFlow has already configured its registration state. You can verify this without any side effects by calling tf.logging.get_verbosity() before adding a filter.

+2
Aug 07 '18 at 19:41
source share

Yes, I am using tf 2.0-beta and want to enable / disable the default logging. The environment variable and methods in tf1.X seem to no longer exist.

I walked around the PDB and found that this works:

 # close the TF2 logger tf2logger = tf.get_logger() tf2logger.error('Close TF2 logger handlers') tf2logger.root.removeHandler(tf2logger.root.handlers[0]) 

Then I add my own logger API (file based in this case)

 logtf = logging.getLogger('DST') logtf.setLevel(logging.DEBUG) # file handler logfile='/tmp/tf_s.log' fh = logging.FileHandler(logfile) fh.setFormatter( logging.Formatter('fh %(asctime)s %(name)s %(filename)s:%(lineno)d :%(message)s') ) logtf.addHandler(fh) logtf.info('writing to %s', logfile) 
+2
Aug 12 '19 at 18:35
source share

I decided with this post I can’t remove all warnings # 27045 , and the solution was:

 import logging logging.getLogger('tensorflow').disabled = True 
+1
Jul 31 '19 at 15:58
source share



All Articles