Tensorflow: TF 1.x: eliminar los mensajes de advertencia "obsoletos"

Creado en 22 mar. 2019  ·  29Comentarios  ·  Fuente: tensorflow/tensorflow

Sé que las API funcionales, como tf.layers.dense, desaparecerán en TF 2.0. Sin embargo, sus alternativas, tf.keras.layers, no son compatibles con otros componentes de TF 1.x, por ejemplo, ni siquiera admiten el alcance variable (# 27016). Así que me quedaré con las API obsoletas en TF 1.x.
¿Podría eliminar los repugnantes mensajes de advertencia "obsoletos" como este: xxx (from tensorflow.python.layers.core) is deprecated and will be removed in a future version. Use keras.layers.xxx instead.

Comentario más útil

En 1.14.0 solo esto funciona:

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

Todos 29 comentarios

Puedes usar esto: -
importar sistema operativo
importar tensorflow como tf
os.environ ['TF_CPP_MIN_LOG_LEVEL'] = '3'

En detalle: -
0 = todos los mensajes se registran (comportamiento predeterminado)
1 = Los mensajes INFO no se imprimen
2 = Los mensajes INFO y ADVERTENCIA no se imprimen
3 = Los mensajes INFO, WARNING y ERROR no se imprimen

esto es lo que he estado usando durante años
no puede detener la advertencia de desaprobación

Por cierto, antes de desaprobar los componentes antiguos, ¿podría completar la funcionalidad actual? Ver # 27042. Parece que TF es muy bueno para desaprobar funciones ampliamente utilizadas, pero pobre para mejorar sus puntos débiles

Los mensajes de obsolescencia son necesarios para informar a las personas que desean utilizar una versión real de TensorFlow sobre lo que sucederá en el futuro y darles tiempo para adaptarse.

Como tal, no podremos eliminar estos mensajes. Puede deshabilitarlos usted mismo usando esta API privada

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

Gracias
Ver # 27045, ¿alguna sugerencia?

Este código me dio un error:

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

Pero cambiar la línea de importación lo hizo funcionar (y suprime las advertencias de desaprobación como se desea):

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

Gracias

@ skylogic004 ¿ es esto de una compilación nocturna reciente / de la fuente del maestro reciente?

@mihaimaruseac Oh, estoy usando tf 1.13 de anaconda (no estoy familiarizado con la rama y compilación de la que vendría originalmente, lo siento, pero ¿tal vez esta es suficiente información para ti?).

$ 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

Enlace al paquete anaconda: https://anaconda.org/anaconda/tensorflow-gpu

Entonces no es algo de lo que deba preocuparme (contexto completo: durante la semana pasada hubo algunas fallas en las importaciones debido a algunos cambios que hice; pero esos son solo en el código maestro, que no parece ser el caso)

Las advertencias de obsolescencia son importantes para los desarrolladores. Puede que no sean tan útiles para los usuarios. Por lo tanto, hay situaciones en las que es conveniente apagarlos.

Python tiene sys.warnoptions que podría establecerse, por ejemplo, a través de PYTHONWARNINGS , por ejemplo:
PYTHONWARNINGS=ignore .

TensorFlow tiene su propia opción TF_CPP_MIN_LOG_LEVEL como se señaló anteriormente.

Y también está la API de registro TensorFlow Python (que creía que funcionaba antes):

import tensorflow as tf

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

El hecho de que ninguna de las opciones anteriores impida que se impriman los mensajes de advertencia parece ser un error.

La bandera _PRINT_DEPRECATION_WARNINGS parece ser interna y puede eliminarse en cualquier momento.

EDITAR: Disculpas, estaba confundiendo los numpy FuturreWarning s con las advertencias de tensorflow. Por lo general, la última opción para establecer el nivel de registro debería funcionar.

En 1.14.0 solo esto funciona:

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

Para r1.14 y posteriores, intente esto:

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

De todos modos, es interno y está sujeto a cambios.

O cambie a TF2.0 donde se eliminan las advertencias de obsolescencia (si no es necesario).

A menos que utilice una buena selección de IDE: p
Lo único que me hizo retroceder fue el problema de autocompletar, por lo que estas solicitudes de supresión son válidas en mi opinión.

El autocompletado se ha resuelto en su mayor parte

Probé todo lo que se ha sugerido:

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

Aún así, tenga un montón de advertencias.

/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 Para las advertencias

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

@ pyotr777 esos vienen de numpy. Estás usando una versión numpy que es ligeramente incompatible con la versión TF que estás usando.

A riesgo de obtener más votos negativos, cambie a 2.0

FuturoAdvertencia

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

no suprimió

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

Para mí, esto funcionó para la advertencia t2.0

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

Para su información, el inicio de sesión en TensorFlow cambió porque TF_CPP_MIN_LOG_LEVEL ya no funciona

Aún así, tenga un montón de advertencias.

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) o '1type' como sinónimo de tipo está en desuso; en una versión futura de numpy, se entenderá como (tipo, (1,)) / '(1,) tipo'.
_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) o '1type' como sinónimo de tipo está en desuso; en una versión futura de numpy, se entenderá como (tipo, (1,)) / '(1,) tipo'.
_np_quint8 = np.dtype ([("quint8", np.uint8, 1)])

Intente uno a la vez para cambiar el 1 a 0, por ejemplo: _np_qint8 = np.dtype ([("qint8", np.int8, 1)]) a _np_qint8 = np.dtype ([("qint8", np.int8 , 0)]) eso me funciona

solve warnings

Estás usando una versión numpy que es ligeramente incompatible con la versión TF que estás usando.

Para mi trabajo poniendo

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

antes de

import tensorflow as tf

y todas las demás importaciones.

Tengo TF 1.14.0 y numpy 1.18.1.

antes de importar tensorflow, debes implementar:
advertencias de importación
warnings.filterwarnings ('ignorar', categoría = FutureWarning)
warnings.filterwarnings ('ignorar', categoría = DeprecationWarning)
funciona para tensorflow == 1.12.0, numpy == 1.18.1, python 3.6

Intenté esto:

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

Y no funcionó para mí cuando ejecuté Python de forma no interactiva tensorflow==1.14.0 , numpy==1.18.1 , python==3.6.10 , pero funcionó en una sesión interactiva.

Descubrí que lo siguiente funcionaba cuando ejecuto Python tanto de forma interactiva como no interactiva. Al usar tensorflow 2.X, puede usar:

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

Y al usar tensorflow 1.X (funcionó en 1.14 para mí):

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

Estoy usando tf 1.13.1
Esto funciona:

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

.compat.v1 no es obligatorio.

Probé todos los métodos, pero ninguno funcionó en el cuaderno jupyter ...

warnings.filterwarnings('ignore',category=FutureWarning)
Esto puede ignorar las advertencias al importar tensorflow, pero todavía existen muchos muchos WARN si cargo el modelo ...

¿Fue útil esta página
0 / 5 - 0 calificaciones