不推荐使用 type 的同义词; 在 numpy 的未来版本中,它将被理解为(type,(1,))/’(1,) type’张量流问题

我安装了 TensorFlow 1.10.1,但当我试图导入 TensorFlow 时,它说我需要 TensorFlow 1.10.0版本。因此,我安装了它,现在我得到了以下警告:

>>> import tensorflow
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
C:\Users\PC\Anaconda3\envs\tut\lib\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)])
64292 次浏览

最新的 numpy 版本(1.17)有:

Future Changes


Shape-1 fields in dtypes won’t be collapsed to scalars in a future version
Currently, a field specified as [(name, dtype, 1)] or "1type" is interpreted
as a scalar field (i.e., the same as [(name, dtype)] or [(name, dtype, ()]).
This now raises a FutureWarning; in a future version, it will be interpreted
as a shape-(1,) field, i.e. the same as [(name, dtype, (1,))] or "(1,)type"
(consistently with [(name, dtype, n)] / "ntype" with n>1, which is already
equivalent to [(name, dtype, (n,)] / "(n,)type").

Https://docs.scipy.org/doc/numpy/release.html

你的表情是这样的:

In [123]: np.dtype([("qint8", np.int8, 1)])
/usr/local/bin/ipython3: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'.
#!/usr/bin/python3
Out[123]: dtype([('qint8', 'i1')])


In [124]: np.dtype([("qint8", np.int8, (1,))])
Out[124]: dtype([('qint8', 'i1', (1,))])


In [125]: np.dtype([("qint8", np.int8)])
Out[125]: dtype([('qint8', 'i1')])


In [126]: np.dtype([("qint8", np.int8, 2)])
Out[126]: dtype([('qint8', 'i1', (2,))])


In [127]: np.__version__
Out[127]: '1.17.0'

这只是个警告,不是错误。它的发生是因为您当前的数字库版本与张量流版本不兼容。你需要降级麻木的版本。

tensorflow 1.10.0numpy<=1.14.5,>=1.13.3的要求,但是您必须安装一些更高的版本(这个警告消息出现在最新的 numpy 版本1.17.0中)。

如果您使用的是 TF 2.0 一个快速的解决办法是降低你的麻木到1.16.4(我使用的是1.17,并且收到了相同的警告消息)。

1. pip uninstall numpy
2. pip install numpy==1.16.4

参见 给你(感谢 ymodak)

pip install "numpy<1.17"

返回到 Numpy 版本 1.16.4

在我的 linux 笔记本电脑中,python3 v3.6中的 tensorflow 也有同样的问题

实际上,您只需要在两个文件中更改一些行:

  • 1

    ~/. local/lib/python3.6/site-package/tensorflow/python/Framework/dtypees.py

以你为例:

C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorflow\python\framework\dtypes.py



现在更改代码: (第516行)

_np_qint8 = np.dtype([("qint8", np.int8, 1)])
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
_np_qint32 = np.dtype([("qint32", np.int32, 1)])




# _np_bfloat16 is defined by a module import.


# Custom struct dtype for directly-fed ResourceHandles of supported type(s).
np_resource = np.dtype([("resource", np.ubyte, 1)])

通过这个密码:

_np_qint8 = np.dtype([("qint8", np.int8, (1,))])
_np_quint8 = np.dtype([("quint8", np.uint8, (1,))])
_np_qint16 = np.dtype([("qint16", np.int16, (1,))])
_np_quint16 = np.dtype([("quint16", np.uint16, (1,))])
_np_qint32 = np.dtype([("qint32", np.int32, (1,))])


# _np_bfloat16 is defined by a module import.


# Custom struct dtype for directly-fed ResourceHandles of supported type(s).
np_resource = np.dtype([("resource", np.ubyte, (1,))])

你必须对这个文件做同样的事情:

  • 2

    ~/. local/lib/python3.6/site-package/tensorboard/compat/tensorflow _ stub/dtypees.py

以你为例:

C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard/compat/tensorflow_stub/dtypes.py

会成功的。

它的发生是因为你的 TensorFlow 版本与 numpy 不兼容。尝试重新安装 numpy 以前的版本。在我的例子中,我试了1.16.4: Pip install numpy = = 1.16.4

但首先,您需要关闭所有正在运行的内核并卸载 numpy,具体步骤如下: Pip 卸载 numpy

或者,人们可以只是沉默的警告:

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

这里提出了这种方法: 如何压制熊猫未来的警告?

您是否安装了多个 numpy 版本,或者有一个与张量流不兼容的 numpy 新版本?

>pip show numpy

或者

import tensorflow as tf
print(tf.__version__)
import numpy as np
print(np.__version__)

将 numpy 版本从 > 1.17降级到1.16.4将解决 Tensorflow 1.14.0的问题

如何降低麻木?

pip uninstall numpy (till you uninstall all versions)
pip install numpy==1.16.4

然后你可以检查它们的兼容性: 之后,请重新启动运行时并执行以下代码

import tensorflow as tf
print(tf.__version__)
import numpy as np
print(np.__version__)