“不赞成使用type的同义词;在numpy的未来版本中,它将被理解为(type,(1,))/'(1,)type'。” TensorFlow中的问题

Emi*_*052 27 python artificial-intelligence numpy python-3.x tensorflow

我安装了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)])
Run Code Online (Sandbox Code Playgroud)

adh*_*dhg 30

如果您使用的是TF 2.0,一种快速的解决方案是将numpy降级为1.16.4。(我使用1.17并收到了相同的警告消息)。

1. pip uninstall numpy 
2. pip install numpy==1.16.4
Run Code Online (Sandbox Code Playgroud)

这里(感谢ymodak)

  • 适用于tensorflow-gpu=1.14 (5认同)
  • 这应该是公认的答案,提供了具体版本。 (2认同)

Anu*_*ngh 22

这只是一个警告,而不是错误。因为您当前的numpy libray版本与tensorflow版本不兼容而发生。您需要降级numpy版本。

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

  • 我不会说绝对有必要从v1.17降级。这里的所有内容看起来像是“ FutureWarning”,而不是“ Error”。如果像我一样,仅使用`FutureWarning`运行代码,则可以坚持使用当前版本。 (3认同)
  • 我应该将 numpy 降级到什么版本? (2认同)

Cha*_*pta 14

pip install "numpy<1.17"
Run Code Online (Sandbox Code Playgroud)

恢复到 Numpy 1.16.4


use*_*262 12

或者,人们可以让警告静音:

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import tensorflow as tf
Run Code Online (Sandbox Code Playgroud)

这里建议使用这种方法:如何抑制熊猫未来警告?


小智 6

我的 linux 笔记本电脑在 python3 v3.6 中使用 tensorflow 时遇到了同样的问题

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

  • 1

    ~/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py

在你的情况下:

C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorflow\python\framework\dtypes.py
Run Code Online (Sandbox Code Playgroud)



现在更改此代码:(第 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)])
Run Code Online (Sandbox Code Playgroud)

通过此代码:

_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,))])
Run Code Online (Sandbox Code Playgroud)

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

  • 2

    ~/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py

在你的情况下:

C:\Users\PC\Anaconda3\envs\tut\lib\site-packages\tensorboard/compat/tensorflow_stub/dtypes.py
Run Code Online (Sandbox Code Playgroud)

它会起作用。


hpa*_*ulj 5

最新的 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").
Run Code Online (Sandbox Code Playgroud)

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'
Run Code Online (Sandbox Code Playgroud)