1

I want to print debugging or logging messages in the Python (high level operations) and C++ (inner operations and kernel implementation) of tensorflow 2.8.0, however neither seems to work.

I tried two builds of tensorflow: the latest version (2.8.0) and the master branch version (2.9)

For Python API logging, I used tf.get_logger().setLevel("DEBUG")

For C++ logging, as mentioned in this stack overflow post or that one, I tried using TF_CPP_MIN_VLOG_LEVEL=2 in two ways:

(1) independently of the code as environment variables: TF_CPP_MIN_VLOG_LEVEL=2; python tf_test.py

(2) Or inside the code using the os module (os.environ['TF_CPP_MIN_VLOG_LEVEL=2']). Tried putting this call before and after importing tensorflow as mentioned here.

However, nothing seems to work.

Here is the example I'm using:

import os 

#os.environ['TF_CPP_MIN_VLOG_LEVEL'] = "2"

import tensorflow as tf

os.environ['TF_CPP_MIN_VLOG_LEVEL'] = "2"

a = tf.Variable(tf.zeros(shape=(2)), name="a")

print(a)

Does anyone have a clue how to make this work?

Shazly
  • 95
  • 1
  • 1
  • 11

1 Answers1

3

After some digging, I worked it out:

TF_CPP_MIN_VLOG_LEVEL has been renamed to TF_CPP_MAX_VLOG_LEVEL. It works only when setting the variable before importing tensorflow.

TF_CPP_MAX_VLOG_LEVEL produces a lot of output regarding the internal C++ operations.

TF_CPP_MIN_LOG_LEVEL controls warnings, info, error messages.

Shazly
  • 95
  • 1
  • 1
  • 11