我知道功能 API,例如 tf.layers.dense,将在 TF 2.0 中消失。 但是,它们的替代品 tf.keras.layers 与 TF 1.x 的其他组件不兼容,例如,它们甚至不支持变量作用域 (#27016)。 因此,我将坚持使用 TF 1.x 中已弃用的 API。
请您删除令人作呕的“已弃用”警告消息,如下所示: xxx (from tensorflow.python.layers.core) is deprecated and will be removed in a future version. Use keras.layers.xxx instead.
这是我多年来一直在使用的
它无法停止弃用警告
顺便说一句,在弃用旧组件之前,您能否完成当前的功能? 见#27042。 TF 似乎很擅长弃用广泛使用的功能,但在改进其弱点方面却很差
需要弃用消息来告知想要使用 TensorFlow 实际版本的人将来会发生什么,并给他们时间去适应。
因此,我们将无法删除这些消息。 您可以使用此私有 API 自行禁用它们
import tensorflow.python.util.deprecation as deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False
谢谢
见#27045,有什么建议吗?
这段代码给了我一个错误:
import tensorflow.python.util.deprecation as deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False
AttributeError: module 'tensorflow' has no attribute 'python'
但是更改导入行使其工作(并根据需要抑制弃用警告):
from tensorflow.python.util import deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False
谢谢
@skylogic004这是从最近的主人最近的每晚/从源代码构建的吗?
@mihaimaruseac哦,我正在使用 anaconda 的 tf 1.13(我不熟悉它最初来自哪个分支和构建,抱歉,但也许这对您来说已经足够了?)。
$ 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
anaconda 包链接: https :
那么这不是我应该担心的事情(完整的上下文:在过去的一周里,由于我所做的一些更改,导入出现了一些失败;但那些只是在主代码上,似乎并非如此)
弃用警告对开发人员很重要。 它们对用户来说可能不是那么有用。 因此,在某些情况下需要关闭它们。
Python 有sys.warnoptions
,例如可以通过PYTHONWARNINGS
,例如:
PYTHONWARNINGS=ignore
。
如前所述,TensorFlow 有它自己的TF_CPP_MIN_LOG_LEVEL
选项。
还有 TensorFlow Python 日志 API(我认为以前有用):
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
上面的选项都没有阻止打印警告消息似乎是一个错误。
_PRINT_DEPRECATION_WARNINGS
标志似乎是内部的,可以随时删除。
编辑:抱歉,我将numpy FuturreWarning s 混淆为 tensorflow 警告。 设置日志记录级别的最后一个选项通常仍然有效。
在1.14.0
仅此有效:
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
对于 r1.14 及更高版本,试试这个:
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
无论如何,这是内部和主题的变化。
或者切换到 TF2.0,其中删除了弃用警告(因为不需要)。
除非您使用了精选的 IDE :p
唯一让我回滚的是自动完成问题,因此这些抑制请求是有效的 imo。
自动补全已经基本解决
尝试了所有建议的内容:
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
尽管如此,还是有一堆警告。
/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
蟒蛇 3.6.8
@pyotr777对于 python 内置警告,您应该使用以下内容来抑制:
warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings('ignore', category=FutureWarning)
@pyotr777那些来自 numpy。 您使用的 numpy 版本与您使用的 TF 版本略有不兼容。
冒着获得更多反对票的风险,请切换到 2.0
未来警告
import warnings
warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings('ignore', category=FutureWarning)
没有压制
/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)])
对我来说,这适用于 t2.0 警告
import tensorflow as tf
tf.get_logger().warning('test')
# WARNING:tensorflow:test
tf.get_logger().setLevel('ERROR')
tf.get_logger().warning('test')
仅供参考 TensorFlow 中的登录更改为 TF_CPP_MIN_LOG_LEVEL 不再工作
尽管如此,还是有一堆警告。
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' 作为类型的同义词已被弃用; 在 numpy 的未来版本中,它将被理解为 (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' 作为类型的同义词已被弃用; 在 numpy 的未来版本中,它将被理解为 (type, (1,)) / '(1,)type'。
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
请一次尝试将 1 更改为 0 例如:_np_qint8 = np.dtype([("qint8", np.int8, 1)]) 到 _np_qint8 = np.dtype([("qint8", np.int8 , 0)]) 对我有用
@TiwaPhil https://github.com/tensorflow/tensorflow/issues/27023#issuecomment -545991801
您使用的 numpy 版本与您使用的 TF 版本略有不兼容。
对我来说工作推杆
import warnings
warnings.filterwarnings('ignore',category=FutureWarning)
前
import tensorflow as tf
和所有其他进口。
我有 TF 1.14.0 和 numpy 1.18.1。
在导入 tensorflow 之前,您应该实现:
进口警告
warnings.filterwarnings('ignore',category=FutureWarning)
warnings.filterwarnings('ignore', category=DeprecationWarning)
它适用于 tensorflow==1.12.0、numpy==1.18.1、python 3.6
我试过这个:
import warnings
warnings.filterwarnings('ignore',category=FutureWarning)
warnings.filterwarnings('ignore', category=DeprecationWarning)
并没有为我工作,当我跑蟒蛇非交互tensorflow==1.14.0
, numpy==1.18.1
, python==3.6.10
,但它在交互式会话没有工作。
我发现当我以交互方式和非交互方式运行 python 时,以下内容都有效。 使用 tensorflow 2.X 时,可以使用:
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR)
当使用 tensorflow 1.X(为我工作 1.14)时:
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
我正在使用 tf 1.13.1
这有效:
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR)
.compat.v1
不是必需的。
我尝试了所有方法,但没有一个在 jupyter notebook 中有效......
warnings.filterwarnings('ignore',category=FutureWarning)
这可以在导入 tensorflow 时忽略警告,但是如果我加载模型,仍然存在许多许多警告...
最有用的评论
在
1.14.0
仅此有效: