How to disable keras warnings?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Keras warnings come from more than one place, so there is no single universal off switch. Some messages are normal Python warnings, some come from TensorFlow's logger, and some are low-level backend logs printed before your model code even runs.
Decide What You Actually Want to Silence
Before disabling anything, identify which kind of output you are seeing:
- Python warnings such as deprecation or user warnings
- TensorFlow logger messages
- low-level C++ backend logs from TensorFlow
That distinction matters because each source uses a different control mechanism. If you suppress the wrong layer, the noisy message will keep appearing and it will look like the filter is broken.
Suppress Python Warnings From Keras
For standard Python warnings, use the warnings module. This is the safest place to start because you can target a category or message pattern instead of hiding everything.
If you really need a broad filter during an experiment, you can ignore all warnings:
That is convenient for quick notebooks, but it is too broad for normal development because it can hide messages that would have warned you about real breakage.
Reduce TensorFlow Log Noise
TensorFlow also writes log messages through its own logger. Those are not controlled by the Python warnings module.
Using "ERROR" keeps only serious log messages. If you still want warnings but not informational output, use "WARNING" instead.
This is useful when Keras model creation triggers extra informational messages that clutter notebook output or CI logs.
Set Backend Log Level Before Importing TensorFlow
Some of the noisiest messages come from the TensorFlow backend and are emitted during import. Those must be controlled with the TF_CPP_MIN_LOG_LEVEL environment variable before TensorFlow is imported.
The common levels are:
- '
0for all logs' - '
1to hide informational logs' - '
2to hide informational and warning logs' - '
3to hide informational, warning, and many error logs'
Use 2 carefully, and use 3 only when you are very sure you do not need backend error details.
A Practical Combined Setup
In many projects, a combined setup gives the cleanest result:
This silences most routine noise while still letting hard failures surface as exceptions.
If you are debugging a model or upgrading TensorFlow, remove these filters temporarily. Keras warnings are often pointing at deprecated APIs, shape mismatches, or behavior changes that you should fix rather than suppress permanently.
Common Pitfalls
- Setting
TF_CPP_MIN_LOG_LEVELafter importing TensorFlow. At that point the import-time backend messages have already been printed. - Ignoring all warnings during active development. That can hide useful deprecation or compatibility signals.
- Assuming Python's
warningsmodule controls TensorFlow logger output. It does not. - Suppressing warning text instead of fixing the underlying deprecated or unsupported API call.
- Using the same notebook kernel after changing environment variables and expecting import-time behavior to change without a restart.
Summary
- Keras output can come from Python warnings, TensorFlow logging, or low-level backend logs.
- Use
warnings.filterwarningsfor Python-side warnings. - Use
tf.get_logger().setLevel(...)for TensorFlow logger messages. - Set
TF_CPP_MIN_LOG_LEVELbefore importing TensorFlow to reduce backend log noise. - Prefer targeted suppression over global silence so important warnings are not lost.

