Tensorflow: FutureWarning:不推荐使用 tf.python.framework.dtypes 中的 numpy API 调用

创建于 2019-07-05  ·  33评论  ·  资料来源: tensorflow/tensorflow

系统信息

  • 我是否编写了自定义代码(而不是使用 TensorFlow 中提供的股票示例脚本):不是真的
  • 操作系统平台和发行版(例如 Linux Ubuntu 16.04):MacOS Mojave 10.14.5 (18F132)
  • TensorFlow 从(源代码或二进制文件)安装:tensorflow==2.0.0b1 from https://pypi.org/
  • TensorFlow 版本(使用下面的命令):v2.0.0-beta0-16-g1d91213fe7 2.0.0-beta1
  • Python 版本:Python 3.6.8
  • Bazel 版本(如果从源代码编译):不适用
  • GCC/编译器版本(如果从源代码编译):不适用
  • CUDA/cuDNN 版本:不适用
  • GPU 型号和内存:不适用

描述当前的行为

大量 FutureWarning 错误:

/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tensorflow-2.0.0b1-py3.6-macosx-10.14-x86_64.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])
/xxx/venv/lib/python3.6/site-packages/tb_nightly-1.14.0a20190603-py3.6.egg/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)])

描述预期行为

没有警告。

重现问题的代码

import tensorflow.python.framework.dtypes

print("Hello world")
TF 2.0 apis awaiting response support

最有用的评论

@Akeaakar目前, pip install "numpy<1.17"恢复到 numpy 版本 1.16.4

所有33条评论

@habernal我们已经在 Google colab 和 Jupyter notebook 中使用 TF 版本执行了您的代码
2.0 beta 1 和 numpy 版本 1.16.4。我们没有收到任何警告。请升级您的 numpy 版本并检查警告是否仍然存在。谢谢!

谢谢, @ravikyram - 我已经仔细检查了已安装的库并找到了罪魁祸首。

TF 2.0.b1 带有 numpy 依赖项 1.16.4,它没有显示任何警告。 所以你不能重现错误是正确的,我也不能。

然而,事实证明我在项目中安装了 numpy 1.17.0rc1(不知道它是从哪个库链接的,因为我当然没有手动安装它)。

Numpy 1.17.0rc1负责抱怨这些 FutureWarnings。 也许现在不急于修复,但一旦升级到 np 17,我想这会再次出现。

实际上,根据您安装 TF 的工具( pipsetuptools ),numpy 依赖项的处理方式不同。 两者都在干净的虚拟环境中进行了测试,一开始只安装了这些库:

pip==19.1.1 setuptools==41.0.1 wheel==0.33.4

  1. 使用pip安装TF:
$ pip install tensorflow==2.0.0b1 --no-cache-dir
...
Collecting numpy<2.0,>=1.14.5 (from tensorflow==2.0.0b1)
  Downloading https://files.pythonhosted.org/packages/...cc/numpy-1.16.4-cp36-cp....whl (13.9MB)
...
  1. 在仅包含以下内容的setup.py中安装 TF 作为依赖项:
from setuptools import setup
setup(
    name='tf30427',
    version='0.0.1',
    install_requires=['tensorflow==2.0.0b1'],
)

然后安装为

$ python setup.py install
...
Searching for numpy<2.0,>=1.14.5
Reading https://pypi.org/simple/numpy/
Downloading https://files.pythonhosted.org/packages/e...17/numpy-1.17.0rc1-cp36-cp36...25e0
Best match: numpy 1.17.0rc1
Processing numpy-1.17.0rc1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Installing numpy-1.17.0rc1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl to /xxx/venv/lib/python3.6/site-packages
Adding numpy 1.17.0rc1 to easy-install.pth file
...

他们以不同的方式理解numpy<2.0,>=1.14.5的要求:pip 安装 1.16.4,而 setuptools 安装 1.17.0rc1。

建议修复:

无论安装过程如何,将依赖项更改为numpy<1.17,>=1.14.5以坚持使用 1.16 版本。

这是问题的核心: https :

其他人也发现了: https :

@habernal让我知道我们是否可以关闭此问题,因为我们找到了解决方案。 谢谢!

@habernal我认为可以更新 tensorflow 以使其与 numpy 1.17+ 兼容。 为修复创建了 PR #30559。

你好,我有同样的错误。 你能告诉我如何处理指令来解决这个问题吗?谢谢

@Akeaakar该问题已修复并合并到主分支中。 在 TF 的下一个版本中,这个问题应该消失了。

@Akeaakar目前, pip install "numpy<1.17"恢复到 numpy 版本 1.16.4

对于 Ubuntu19.04,tensorflow-gpu 1.14.0(或 tensorflow-gpu 1.12.2)与 numpy 1.17.0 的组合也有相同的警告。 当将 numpy 版本更改为 1.16.3 时,警告消失了。

或者您可以使用以下代码抑制警告。

import warnings
import tensorflow as tf

warnings.filterwarnings('ignore')

或者您可以使用以下代码抑制警告。

import warnings
import tensorflow as tf

warnings.filterwarnings('ignore')

似乎这对我不起作用。 (numpy1.17.0 python3.7.3)

或者您可以使用以下代码抑制警告。

import warnings
import tensorflow as tf

warnings.filterwarnings('ignore')

似乎这对我不起作用。 (numpy1.17.0 python3.7.3)

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

需要在导入之前,因为这是警告的来源。 还添加了一个限制,仅影响该警告类别,而不是使所有警告静音。

进口警告
warnings.filterwarnings('忽略',category=FutureWarning)
将张量流导入为 tf
即使在虚拟环境下它也适用于我

我在 ./venv/lib/python3.7/site-packages (1.17.2) 中有 numpy。 在 Jupyter 和 VS Code 中,我都明白了。 我真的不喜欢忽略警告的想法。 任何修复将不胜感激。

pip 安装“numpy<1.17”

这样做之后,系统安装了numpy-1.16.5 。 但现在import tensorflow说:
ImportError: Something is wrong with the numpy installation.

麻木: pip install --upgrade numpy
keras: conda install -c conda-forge keras

在 Anaconda 提示符下使用上述命令升级您的 numpy 并安装 keras。

嗨,作为参考,我用这两个版本修复了这个问题:

>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0-rc1
>>> import numpy as np
>>> print(np.__version__)
1.17.2
>>> exit()

09/24/19,希望这有帮助

谢谢@Namburger 。 警告在 2.0.0-rc1 上消失了。

随着最新版本的 tensorflow(即 2.0.0)和 numpy 1.17.2,警告又回来了。

你能提供一个复制器, @UndeadKernel吗? 我无法重现:

>>> import tensorflow as tf
>>> tf.__version__
'2.0.0'
>>> import numpy as np
>>> np.__version__
'1.17.2'
>>> import tensorflow.python.framework.dtypes
>>> 

还从文件中尝试过:

import tensorflow as tf
import numpy as np

print("TF", tf.__version__)
print("NP", np.__version__)

import tensorflow.python.framework.dtypes

但没有警告:

(gh_numpty) mihaimaruseac<strong i="13">@ankh</strong>:/tmp/gh_numpty$ python test.py 
TF 2.0.0
NP 1.17.2

@mihaimaruseac ,我可以用你的两个例子重现这个问题。 也就是说,我看到以下输出:

2019-10-14 12:20:56.438892: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
/usr/lib/python3.7/site-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/lib/python3.7/site-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/lib/python3.7/site-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/lib/python3.7/site-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/lib/python3.7/site-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/lib/python3.7/site-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 2.0.0
NP 1.17.2

我正在使用拱门。 如果我没记错的话,Arch 使 Tensorflow 适应了 Python 3.7.4。 或者这个版本的 Python 已经被 Tensorflow 支持了吗?

@UndeadKernel我也在运行 Arch,但

  • python-tensorflow-opt-cuda:2.0.0-2
  • python-numpy-openblas:1.17.2-1

这确实很奇怪@rharish101 ,我有完全相同的版本。 我尝试使用来自官方仓库的python-numpy和来自 AUR 的 python-numpy-openblas`,我看到了相同的 FutureWarning 消息。

@UndeadKernel您可以尝试重新安装 TensorFlow 软件包吗? 它可能在最新的补丁(2.0.0-2 而不是 2.0.0-1)中发生了变化。 我记得我前几天也看到了那些警告,但截至今天,它们已经消失了,唯一的区别是我在 9 天前更新了 TensorFlow。

@rharish101 ,感谢您的建议。
我注意到tensorboardtensorflow 。 重新安装tensorboard (注意这是“tensorBoard”而不是“TensorFlow”)后,警告消失了。

有一个 2.0 的正式版本,您应该不需要使用打过补丁的版本。

你指的是哪些补丁@mihaimaruseac?

上面评论中提到的 2.0.0-1 和 2.0.0-2

pip install tensorflow==2.0.0应该可以工作(如果您使用的是旧版本,则可能需要将 pip 升级到最新版本,因为更改为符合 manylinux2010)

尝试

pip3 [pip] 安装 tf-nightly

tensorflow 的夜间构建似乎已经解决了这个问题,祝你好运

对于tensorflow==2.0.0numpy==1.17.4

我没有收到错误/警告。

您可以尝试如下:

>>> import tensorflow as tf
>>> tf.__version__
'2.0.0'
>>> import numpy as np
>>> np.__version__
'1.17.4'
>>> import tensorflow.python.framework.dtypes
>>>

@Akeaakar目前, pip install "numpy<1.17"恢复到 numpy 版本 1.16.4

也适用于蟒蛇:
conda install "numpy<1.17"

目前, pip install "numpy<1.17"恢复到 numpy 版本 1.16.4

几个小时后,这是解决我问题的那个。 我安装了安装了 numpy 版本(18.0)的 TF,当我将它恢复到 1.16.4 时,它可以工作了! 谢谢

此页面是否有帮助?
0 / 5 - 0 等级