TensorFlow
Keras
verbose messages
machine learning
debugging

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.

Practice ML system design

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:

text
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 25ms/step

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.

python
1import numpy as np
2import tensorflow as tf
3
4x = np.random.rand(32, 4).astype("float32")
5y = np.random.randint(0, 2, size=(32, 1)).astype("float32")
6
7model = tf.keras.Sequential([
8    tf.keras.layers.Input(shape=(4,)),
9    tf.keras.layers.Dense(8, activation="relu"),
10    tf.keras.layers.Dense(1, activation="sigmoid"),
11])
12
13model.compile(optimizer="adam", loss="binary_crossentropy")
14model.fit(x, y, epochs=2, verbose=0)
15predictions = model.predict(x[:4], verbose=0)
16print(predictions.shape)

Typical settings are:

  • 'verbose=0 for silent'
  • 'verbose=1 for progress bars'
  • 'verbose=2 for 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.

python
1import logging
2import tensorflow as tf
3
4tf.get_logger().setLevel(logging.ERROR)

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.

python
import tensorflow as tf

tf.keras.config.disable_interactive_logging()

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.

python
1import os
2
3os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
4
5import tensorflow as tf

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 hide INFO'
  • '"2" to hide INFO and WARNING'
  • '"3" to hide INFO, WARNING, and ERROR'

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:

python
1import os
2import logging
3
4os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
5
6import tensorflow as tf
7
8tf.get_logger().setLevel(logging.ERROR)
9tf.keras.config.disable_interactive_logging()
10
11model = tf.keras.Sequential([
12    tf.keras.layers.Input(shape=(4,)),
13    tf.keras.layers.Dense(1),
14])
15
16model.compile(optimizer="adam", loss="mse")

Then, on individual calls, still set:

python
model.fit(x, y, verbose=0)
model.predict(x, verbose=0)

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=0 to silence Keras fit(), evaluate(), and predict() 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_LEVEL before importing TensorFlow to reduce backend startup logs.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Practice ML system design

All Rights Reserved.