python - 禁用 TensorFlow/Numpy 弃用警告消息
问题描述
运行使用tensorflow
v1.14.0 的 Python 3.7.4 应用程序会导致出现大量弃用警告。以下代码清除了大部分内容。
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
但是,不会删除任何警告。更新tensorflow
到 v2.x 现在不是一个选项。
如何删除这些消息?
警告信息:
/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.
解决方案
您可以通过将以下代码放在脚本的开头(源代码)来忽略所有“FutureWarning”警告:
from warnings import simplefilter
simplefilter(action='ignore', category=FutureWarning)
请注意,您必须将这些行放在任何其他导入之前,因为其中一些可能已经自己导入依赖项。
推荐阅读
- javascript - 有人知道如何在数组中添加额外的逗号和字符串吗?
- node.js - NodeJS - for 循环内的嵌套 Promise
- javascript - _redux_redux_store__WEBPACK_IMPORTED_MODULE_2___default.a.getState 不是函数
- python - 如何在 Python 中使用 AWS CDK 创建涉及两个属性的 SNS 订阅过滤器?
- java - Java中的OpenPGP公钥导入
- c++ - CStdioFile 不能处理大于 2GB 的文件?
- git - 在 Github Actions 中为 [not] 来自 fork 的 PR 获取目标分支 ref
- symfony - Symfony 基于角色的路由重定向
- python - python regex 模块可以匹配非 utf 编码的模式吗?
- python - 其他声明表现得好像它不存在