[警告] FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future ver

警告信息

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

系统环境

  • Ubuntu 18.4 LTS
  • Python 3.6
  • TensorFlow 2.0.0-beta1
  • NumPy 1.17.2

原因分析

TensorFlow 2.0.b1的版本下,如果Numpy的版本超过了1.17,那么就会出现这个警告。
这个问题已经在 GitHub 的 PR #30559 [2] 中得到了解决,不出意外的话,在TensorFlow的下个版本中,应该就不会再出现这个警告了。

解决方案

有如下三种临时解决方案:

1. 回退版本

既然高版本(Numpy 1.17.0rc1)会报错,那么稍微降低版本不就可以了!?!

pip install "numpy<1.17"

2. 暂时忽略报错

根据网友 njanirudhGra-tak解决方案 [1],暂时忽略报错是一个不错的选择,毕竟这个报错目前还没有负面影响。在导入tensorflow之前,导入warnings包:

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

import tensorflow as tf

当然,这会暂时忽略所有的FutureWarning报错。

3. 物我两忘

它报任它报,物我而兼忘。

更新

实测TensorFlow 2.0.0-rc1不会报警告。

Reference

  1. njanirudh, Gra-tak. (September 22, 2019). FutureWarning: Deprecated numpy API calls in tf.python.framework.dtypes. Retrieved from https://github.com/tensorflow/tensorflow/issues/30427
  2. yongtang. (September 22, 2019). Fix numpy warning with numpy 1.17.0+. Retrieved from https://github.com/tensorflow/tensorflow/pull/30559
  • 14
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
这个警告信息是关于NumPy库的一个即将被弃用的用法。在将来的NumPy版本中,传递`(type, 1)`或`'1type'`会被理解为`(type, (1,))`或`'(1,)type'`。 要解决这个警告,你可以尝试以下几种方法: 1. 更新NumPy库:确保你正在使用最新版本的NumPy库。你可以使用以下命令来更新NumPy: ``` pip install --upgrade numpy ``` 这将会安装最新版本的NumPy库,其中包含对这个警告的修复。 2. 忽略警告:如果你确定代码的其他部分正常工作,你可以选择忽略这个警告。可以通过在代码开头添加以下代码来忽略警告: ```python import warnings warnings.filterwarnings("ignore", category=FutureWarning) ``` 这会将`FutureWarning`类别的警告忽略掉。 3. 修改代码:如果你有直接控制代码的权限,你可以尝试修改代码以避免出现这个警告。具体的修改方式取决于你的代码逻辑和使用到的NumPy函数。一种可能的修改方法是使用`(type, (1,))`代替`(type, 1)`。 例如,如果你有以下代码: ```python _np_qint8 = np.dtype([("qint8", np.int8, 1)]) ``` 你可以将其修改为: ```python _np_qint8 = np.dtype([("qint8", np.int8, (1,))]) ``` 这样就避免了警告。 尝试上述方法后,应该可以解决`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'.`的问题。如果还有其他问题,请告诉我,我将尽力帮助你。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Xovee

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值