Suppressing Tensorflow Logs

If you’ve used tensorflow to build your Machine Learning models or used it as a back-end with Keras, you’ve definitely encountered a whole lot of debugging info that’s output to the terminal before your program begins execution. These are sometimes error messages, most of the time warnings and in some cases additional info as well and can be extremely useful. But in most cases all you really care about is observing the output from your program than wade through a whole lot of tensorflow jargon about how you can improve computation speed (which in fact is pretty important).

Before we know how to suppress the debugging info that tensorflow outputs, let’s know a bit about them. If you observe every message that tensorflow throws at you, you’ll notice that they are prefixed with an I(Info), W(Warning) or an E(Error) that signifies what the message really is about. Now what debugging info tensorflow is supposed to tell you is controlled by the TF_CPP_MIN_LOG_LEVEL environment variable.

How do we do this in python? Simple. Just add these two lines on top of your code.

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

You can read this stack overflow post for more.