Tensorflow: TF 1.x: remove the "deprecated" warning messages

Created on 22 Mar 2019  ·  29Comments  ·  Source: tensorflow/tensorflow

I know the functional APIs, such as tf.layers.dense, will disappear in TF 2.0. However, their alternatives, tf.keras.layers, are not compatible with other components of TF 1.x, for example, they even do not support variable scope (#27016). So I will stick on the deprecated APIs in TF 1.x.
Would you please remove the disgusting "deprecated" warning messages like this: xxx (from tensorflow.python.layers.core) is deprecated and will be removed in a future version. Use keras.layers.xxx instead.

Most helpful comment

On 1.14.0 only this works:

import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)

All 29 comments

You can use this:-
import os
import tensorflow as tf
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

In detail:-
0 = all messages are logged (default behavior)
1 = INFO messages are not printed
2 = INFO and WARNING messages are not printed
3 = INFO, WARNING, and ERROR messages are not printed

this is what i have been using for years
it cannot stop the deprecation warning

By the way, before deprecating old components, would you please complete the current functionality? See #27042. It seems that TF is very good at deprecating widely used functions, but poor at improving its weak points

Deprecation messages are needed to inform people who want to use an actual version of TensorFlow what is going to happen in the future, and give them time to adapt.

As such, we won't be able to remove these messages. You can disable them for yourself using this private API

import tensorflow.python.util.deprecation as deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False

Thanks
See #27045, any suggestions?

This code gave me an error:

import tensorflow.python.util.deprecation as deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False
AttributeError: module 'tensorflow' has no attribute 'python'

But changing the import line made it work (and suppresses the deprecation warnings as desired):

from tensorflow.python.util import deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False

Thanks

@skylogic004 is this from a recent nightly/build from source from recent master?

@mihaimaruseac Oh, I'm using tf 1.13 from anaconda (I'm not familiar with what branch & build it would have come from originally, sorry, but maybe this is enough info for you?).

$ python
Python 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 11:48:23) [MSC v.1900 64 bit (AMD64)] on win32  
Type "help", "copyright", "credits" or "license" for more information.                                          
>>> import tensorflow as tf                                                                                     
>>> tf.__version__                                                                                              
'1.13.1'                                                                                                        

$ conda list | grep tensor
tensorboard               1.13.1           py36h33f27b4_0
tensorflow                1.13.1          gpu_py36h1635174_0
tensorflow-base           1.13.1          gpu_py36h0fff12a_0
tensorflow-estimator      1.13.0                     py_0
tensorflow-gpu            1.13.1               h0d30ee6_0

Link to anaconda package: https://anaconda.org/anaconda/tensorflow-gpu

Then it's not something I should worry about (full context: over the past week there have been some failures on imports due to some changes I made; but those are only on master code, which doesn't seem to be the case)

Deprecation warnings are important for developers. They may not be all that useful to users. Therefore there are situations where it is desirable to switch them off.

Python has sys.warnoptions which could be for example set via PYTHONWARNINGS, e.g.:
PYTHONWARNINGS=ignore.

TensorFlow has it's own TF_CPP_MIN_LOG_LEVEL option as pointed out earlier.

And there is also the TensorFlow Python logging API (which I believed worked before):

import tensorflow as tf

tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)

That none of the options above are preventing the warning messages from being printed seem to be a bug.

The _PRINT_DEPRECATION_WARNINGS flag seems to be internal and may be removed any time.

EDIT: Apologies, I was confusing the numpy FuturreWarnings for tensorflow warnings. The last option to set the logging level should generally still work.

On 1.14.0 only this works:

import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)

For r1.14 and onward, try this:

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

Anyway, it is internal and subjects to change.

Or switch to TF2.0 where deprecation warnings are removed (as not needed).

Unless you use a good selection of IDE's :p
Only thing that made me roll back was the autocomplete issue so these suppression requests are valid imo.

Autocompletion has been mostly solved

Tried all of what have been suggested:

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
from tensorflow.python.util import deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False
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

Still, have a pile of warnings.

/usr/local/lib/python3.6/dist-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)])
/usr/local/lib/python3.6/dist-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)])
/usr/local/lib/python3.6/dist-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)])
/usr/local/lib/python3.6/dist-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)])
/usr/local/lib/python3.6/dist-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)])
/usr/local/lib/python3.6/dist-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)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: 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)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: 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)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: 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)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: 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)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: 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)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: 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)])
TF version 1.14.0

Ubuntu 16.04
Python 3.6.8

@pyotr777 For python builtin warnings, you should use following to suppress:

warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings('ignore', category=FutureWarning)

@pyotr777 those come from numpy. You are using a numpy version that is slightly incompatible with the TF version you're using.

At the risk of getting more downvotes, please switch to 2.0

FutureWarning

import warnings
warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings('ignore', category=FutureWarning)

did not supress

/usr/local/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)])

For me this worked for t2.0 warning

import tensorflow as tf
tf.get_logger().warning('test')
# WARNING:tensorflow:test
tf.get_logger().setLevel('ERROR')
tf.get_logger().warning('test')

FYI Logging in TensorFlow changed as TF_CPP_MIN_LOG_LEVEL is not working Anymore

Still, have a pile of warnings.

/usr/local/lib/python3.6/dist-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)])
/usr/local/lib/python3.6/dist-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)])

Please tried one at a time to change the 1 to 0 eg: _np_qint8 = np.dtype([("qint8", np.int8, 1)]) to _np_qint8 = np.dtype([("qint8", np.int8, 0)]) that works for me

solve warnings

You are using a numpy version that is slightly incompatible with the TF version you're using.

For me worked putting

import warnings
warnings.filterwarnings('ignore',category=FutureWarning)

before

import tensorflow as tf

and all other imports.

I have TF 1.14.0 and numpy 1.18.1.

before import tensorflow, you should implement:
import warnings
warnings.filterwarnings('ignore',category=FutureWarning)
warnings.filterwarnings('ignore', category=DeprecationWarning)
it works for tensorflow==1.12.0, numpy==1.18.1, python 3.6

I tried this:

import warnings
warnings.filterwarnings('ignore',category=FutureWarning)
warnings.filterwarnings('ignore', category=DeprecationWarning)

And it did not work for me when I ran python non-interactively tensorflow==1.14.0, numpy==1.18.1, python==3.6.10, but it did work in an interactive session.

I found that the following worked when I run python both interactively and non-interactively. When using tensorflow 2.X, you can use:

import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR)

And when using tensorflow 1.X (worked on 1.14 for me):

import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)

I'm using tf 1.13.1
This works:

import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR)

.compat.v1 is not required.

I tried all methods, but none of them worked in jupyter notebook...

warnings.filterwarnings('ignore',category=FutureWarning)
This can ignore warnings when importing tensorflow, but there still exists many many many WARN if i load model...

Was this page helpful?
0 / 5 - 0 ratings