Running my Python 3.7.4 app that uses tensorflow
v1.14.0 causes a large list of deprecation warnings to appear. The following code clears up most of it.
try:
from tensorflow.python.util import module_wrapper as deprecation
except ImportError:
from tensorflow.python.util import deprecation_wrapper as deprecation
deprecation._PER_MODULE_WARNING_LIMIT = 0
However, none of the warnings are removed. Updating tensorflow
to v2.x is not an option right now.
How can these messages be removed?
Warning messages:
/anaconda3/envs/ml/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/anaconda3/envs/ml/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/anaconda3/envs/ml/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/anaconda3/envs/ml/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/anaconda3/envs/ml/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/anaconda3/envs/ml/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
WARNING:tensorflow:From /Users/x/foo/dnnlib/tflib/tfutil.py:34: The name tf.Dimension is deprecated. Please use tf.compat.v1.Dimension instead.
WARNING:tensorflow:From /Users/x/foo/dnnlib/tflib/tfutil.py:74: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.
WARNING:tensorflow:From /Users/x/foo/dnnlib/tflib/tfutil.py:128: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.
You can ignore all "FutureWarning" warnings by putting the following code at the beginning of your scripts (source):
from warnings import simplefilter
simplefilter(action='ignore', category=FutureWarning)
Please note that you have to put those lines before any other imports as some of those might already import dependencies on their own.
The issue that brought me here was actually for a recent numpy deprecation warning coming from code in tensorboard
, but I expect that the principles comes to bear on the question in the OP as well.
Adding the following before any tensorflow
imports will suppress developer-directed DeprecationWarnings
arising from that specific module (DeprecationWarnings are ignored by default, but they might be turned on, e.g., by QA tools; use FutureWarnings
instead if the deprecation warnings are directed at end-users):
from warnings import filterwarnings # noqa
warnings.filterwarnings(action='ignore',
category=DeprecationWarning,
module='tensorflow') # noqa
__init__.py
file (after any __future__
imports).black
or autopep8
) may push these lines after the offending import. Since I'm use an autopep8-on-save trigger in VSCode, I also needed to add the # noqa
to the import and filter lines so that they were not moved (see this post). To avoid needing to squelch linting error for the following imports, another option is to move the warning filtering lines to a separate python file and then import that from __init__.py
(see this post).tensorboard
issue, I used module='tensorboard'
instead.)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With