Keras
warnings
disable
how-to
Python

How to disable keras warnings?

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

Keras warnings can come from several layers of the stack: Python warnings, TensorFlow log messages, and lower-level backend logging. "Disable Keras warnings" is therefore not one switch but a choice about which messages you want to suppress. The safest approach is to silence only the specific category that is noisy, rather than muting everything globally.

Distinguish Warnings From TensorFlow Logs

There are two broad sources of console noise:

  • Python warnings such as UserWarning or DeprecationWarning
  • TensorFlow runtime logs printed by the backend

These are controlled differently. If you mix them together, you may think one setting is broken when it is simply targeting the wrong source.

Suppress Specific Python Warning Categories

For Python-level warnings, use the standard warnings module.

python
1import warnings
2
3warnings.filterwarnings("ignore", category=UserWarning, module="keras")
4warnings.filterwarnings("ignore", category=FutureWarning, module="tensorflow")

This is better than ignoring all warnings blindly because it keeps unrelated warnings visible.

If you really want to suppress all Python warnings in a short-lived experiment, you can do:

python
import warnings

warnings.filterwarnings("ignore")

That is blunt and should usually be temporary.

Reduce TensorFlow Backend Logging

Many messages that people call "Keras warnings" are actually TensorFlow logs. These are commonly controlled with TF_CPP_MIN_LOG_LEVEL, and it must be set before importing TensorFlow.

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

The usual meanings are:

  • '"0" shows all logs'
  • '"1" hides INFO'
  • '"2" hides INFO and WARNING'
  • '"3" hides INFO, WARNING, and ERROR logs from the C++ side'

Use "2" carefully. It is often enough to reduce noise without hiding every serious clue.

Control TensorFlow Logger Verbosity

TensorFlow also exposes a Python logger.

python
1import os
2os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
3
4import tensorflow as tf
5
6tf.get_logger().setLevel("ERROR")

This can reduce additional Python-side logging that is not handled purely by the environment variable.

Use Targeted Suppression During Model Code

If a single block is noisy, you can narrow the suppression scope instead of changing the whole process.

python
1import warnings
2import tensorflow as tf
3
4with warnings.catch_warnings():
5    warnings.simplefilter("ignore", category=UserWarning)
6    model = tf.keras.Sequential([
7        tf.keras.layers.Input(shape=(10,)),
8        tf.keras.layers.Dense(16, activation="relu"),
9        tf.keras.layers.Dense(1)
10    ])

This is useful when a notebook cell or one legacy function emits a warning you already understand and accept.

Do Not Suppress Deprecation Warnings Too Early

Deprecation warnings are often useful because they tell you a future upgrade will break something. If you suppress them globally, you may lose the only early signal that the code needs modernization.

A better pattern is:

  • fix the warning if practical
  • suppress it only if it is known, understood, and currently unavoidable

That keeps the logs cleaner without hiding maintenance issues completely.

A Practical Quiet Setup

For experiments where TensorFlow is too noisy but you still want Python warnings under control, this is a reasonable starting point:

python
1import os
2import warnings
3
4os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
5
6warnings.filterwarnings("ignore", category=UserWarning, module="keras")
7
8import tensorflow as tf
9tf.get_logger().setLevel("ERROR")

That combination usually removes most routine noise while still allowing fatal failures to surface.

Common Pitfalls

The biggest mistake is setting TF_CPP_MIN_LOG_LEVEL after importing TensorFlow, which is too late for many backend messages. Another is suppressing every Python warning globally and then missing real compatibility problems. Developers also confuse TensorFlow logs with warnings.warn output and expect one mechanism to silence both. If the noise is coming from only one repeated warning, use a targeted filter instead of muting the whole runtime.

Summary

  • Keras-related noise may come from Python warnings or TensorFlow logs.
  • Use the warnings module for Python warning categories.
  • Set TF_CPP_MIN_LOG_LEVEL before importing TensorFlow to reduce backend log noise.
  • Use tf.get_logger().setLevel(...) for additional Python-side TensorFlow logging control.
  • Prefer targeted suppression over global muting.
  • Be careful not to hide deprecation warnings that signal real upgrade work.

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.