How to avoid tensorflow print on standard error

Many of us must have noticed the below statement at the beginning of your assignment notebook :point_down:
os.environ[‘TF_CPP_MIN_LOG_LEVEL’] = ‘3’

and wondered its significance like me!!!

If using TensorFlow 2.0+, make sure to put those lines before import tensorflow to be effective.

To disable all logging output from TensorFlow, set the following environment variable before launching Python:

$ python ...

You can also adjust the verbosity by changing the value of TF_CPP_MIN_LOG_LEVEL:

  • 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


1 Like

See silence-tensorflow

1 Like

Hey @balaji.ambresh

Thank you for the share.

is this compatible with the latest version of tensfor flow??

if this is the latest version, then why was it not used in the assignments we are doing like NLP or other short course.

Thank you in advance.


You’re welcome.
It’s compatible with the latest version of tensorflow.
You have access to this private LT lead listing page. That’s a good place to start as well.

Adding @arvyzukai regd. NLP.

1 Like

He is on vacation otherwise I would have asked him already :slight_smile:

as I have noticed TF_CPP_MIN_LOG_LEVEL many places, never came across silence-tensorflow, so was wondering but what I understood

with silence-tensorflow
This package will set the KMP_AFFINITY system variable to “noverbose”, TF_CPP_MIN_LOG_LEVEL to level 3 (only errors logged).

this is the difference between these two.


1 Like

It’s okay for him to get back from vacation and notify the staff since this is not an urgent change.

1 Like

I’m back :slight_smile:

I’m no expert on TensorFlow :innocent:.
As far as I understand your question - you are asking about the reasons behind the log level that was chosen in the Notebooks?
My understanding of this is very “surface level” and my thoughts are that the number of messages(info, warning, errors) they (the course developers) wanted to display depends on the Notebooks and the system they tested. In other words, each notebook would have it’s own reasons (the frameworks’ versions, the functions used, the “tolerance” of the learners (beginner courses might suppress all messages, while more advanced courses might show some messages that could be of some use), and maybe “just because” :slight_smile:).
Again, I’m not the most informed on the matter, just my thoughts.


1 Like

Hi arvy @arvyzukai :raising_hand_woman:t2:

Good to have you back.

I wasn’t asking query here :grin:.

If you notice my first post comment here, it mentions if someone comes across this doubt they can refer about the log level.

I did research myself arvy, and I don’t know if you remember one of the learner in short course had a similar query about the warning, related to or prevent fast tokenization, so I came across similar codes again in one of the notebook and I wondered it’s significance and I came forth the information which I shared, so if any learners has doubt can search through.

But then the good part of posting this was I got to know silence tensorflow by balaji, and that’s when I asked him, when that use of import silence tensor flow could directly avoid all the 3 levels of information related to tensor flow, then why wasn’t it used in our assignments as I noticed in recent updated assignments of NLP.
That’s when he tagged you, he didn’t knew I was already annoying you with doubts :joy:

Anyways, so can you tell me why was silence tensorflow not preferred in the updated assignments, although I can intuitively know what you might tell :rofl: but I am still waiting for your response too on this

Hope you had a great vacation :national_park:


Hi @Deepti_Prasad

I’m not sure what you have in mind :sweat_smile: . silence-tensorflow is a third party package and uses them (third party code) very sparingly/cautiously.

Maybe what you meant is that TensorFlow is not my first (or second…) choice when it comes to DL, and the TF approach to “things” is not my favorite?

On the other hand, I personally lean towards more logging than less, so in that regard I usually find logging messages more useful than scary (while I understand that some learners might find them disturbing). In other words, if they would not interfere too much with the learning materials (not sure of how many of them would show up), I would prefer to see them than not.


1 Like

Okay understood.

I thought you would again tease me on tensorflow :face_with_peeking_eye:

Thank you both, understood the silence-tensorflow, thank you @balaji.ambresh for that, and thank you arvy :grin:


1 Like

:sweat_smile: ah… in that case I understand that I’m a rabbit between two lions of TF and any misstep might be the last… :stuck_out_tongue_winking_eye:

1 Like