How to get rid of tensorflow verbose messages with Keras
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
When people say TensorFlow is "too verbose," they are often mixing together three different kinds of output: Keras progress bars, TensorFlow Python logger messages, and low-level TensorFlow backend logs. The fix depends on which one you actually want to suppress, because each source is controlled differently.
Know Which Output You Are Seeing
Before changing settings, identify the source:
- Keras training and prediction progress, such as epoch bars
- TensorFlow Python warnings and informational logs
- TensorFlow backend messages printed during import or device initialization
These are related, but not the same.
For example, this output:
comes from Keras verbosity settings, not from the TensorFlow backend logger.
By contrast, device and runtime startup messages usually come from TensorFlow itself.
Suppress Keras Progress Output
Keras methods such as fit(), evaluate(), and predict() accept a verbose argument. If the noise you want to remove is the progress bar, this is the first place to look.
Typical settings are:
- '
verbose=0for silent' - '
verbose=1for progress bars' - '
verbose=2for one line per epoch'
If the complaint is only about progress bars, verbose=0 is enough.
Control TensorFlow Python Logging
TensorFlow exposes a logger through tf.get_logger(). The official API allows setting the logger level directly.
That suppresses lower-severity messages such as INFO and WARNING coming through the TensorFlow logger. It does not silence Keras progress bars, because those are a separate output path.
This is a good choice when you still want actual errors to be visible but do not want routine informational chatter.
Disable Interactive Keras Logging
Current Keras also exposes interactive logging controls. tf.keras.config.disable_interactive_logging() switches Keras away from stdout-oriented interactive output and sends logs to absl.logging, which is usually a better fit for non-interactive scripts and server jobs.
This is useful when you run training in batch jobs, CI, or remote processes and want cleaner logs.
It is not the same as verbose=0. Think of it as changing the logging style and destination rather than simply removing per-call progress output.
Suppress Low-Level TensorFlow Backend Logs
Some of the noisiest TensorFlow messages appear before you even create a model. Those often come from the C++ backend. For that class of output, set TF_CPP_MIN_LOG_LEVEL before importing TensorFlow.
The important detail is ordering: the environment variable must be set before import tensorflow as tf. If you set it afterward, the startup logs have already happened.
Common values are:
- '
"0"to show everything' - '
"1"to hideINFO' - '
"2"to hideINFOandWARNING' - '
"3"to hideINFO,WARNING, andERROR'
In most cases, "2" is a reasonable ceiling. Hiding errors as well is risky because it can make debugging much harder.
A Practical Combined Setup
If you want a quiet script without completely blinding yourself, combine the settings deliberately:
Then, on individual calls, still set:
That combination usually gives the cleanest output for scripts and tests.
Do Not Suppress Everything by Default
Silencing logs too aggressively is tempting, but it comes with a cost. Warnings about missing accelerators, numerical instability, or deprecated APIs can matter.
A practical rule is:
- silence progress bars in production jobs
- reduce informational logs in stable pipelines
- keep warnings visible while developing
If a notebook or experiment suddenly behaves differently after an environment change, overly aggressive log suppression can hide the clue you needed.
Common Pitfalls
The most common mistake is setting TF_CPP_MIN_LOG_LEVEL after importing TensorFlow. That does not suppress the startup noise that has already been emitted.
Another issue is expecting tf.get_logger().setLevel(...) to remove Keras progress bars. It will not. Progress output is controlled by verbose and Keras logging settings.
Developers also sometimes set the C++ log level to "3" and then wonder why important failures disappear from the console. That level can hide real problems.
Finally, some code samples online use outdated logging approaches from older TensorFlow versions. For current TensorFlow and Keras, prefer tf.get_logger(), tf.keras.config.disable_interactive_logging(), and per-call verbose control.
Summary
- TensorFlow verbosity comes from more than one source, so there is no single universal mute switch.
- Use
verbose=0to silence Kerasfit(),evaluate(), andpredict()progress output. - Use
tf.get_logger().setLevel(logging.ERROR)to reduce TensorFlow Python logger noise. - Use
tf.keras.config.disable_interactive_logging()when running Keras non-interactively. - Set
TF_CPP_MIN_LOG_LEVELbefore importing TensorFlow to reduce backend startup logs.
Related reading
- How to get stable results with TensorFlow, setting random seed
- how to get string value out of tf.tensor which dtype is string
- How to get summary information on tensorflow `RNN`
- How to get Tensorflow tensor dimensions shape as int values?
- How to get sample weights and class weights for multi-label classification problem?
- How to get SVMs to play nicely with missing data in scikit-learn?
- How to get rid of would clobber existing tag
- How to get status code from webclient?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.